rofile或FirefoxOptions通过Selenium设

rofile或FirefoxOptions通过Selenium设

本文介绍了如何使用FirefoxProfile或FirefoxOptions通过Selenium设置Firefox浏览器的窗口位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过使用以下命令创建驱动程序来更改Firefox窗口的位置:

I need to change the position of the Firefox window by creating the driver with:

driver = webdriver.Firefox()

我知道在创建驱动程序之后可以更改窗口位置:

I know it's possible to change the window position after the driver was created:

driver.set_window_position()

我无法找到使用Firefox配置文件或选项的方法:

I can't find out how to do it using Firefox profile or options:

profile = webdriver.FirefoxProfile()
profile.set_preference("some_preference", my_preference)

options = Options()
options.some_optins = my_options

最后:

driver = Webdriver.Firefox(firefox_profile=profile, options=options)

推荐答案

您看对了.

set_window_position() 设置当前窗口的xy位置.

  • 实施:

  • Implementation:

set_window_position(x, y, windowHandle='current')
Sets the x,y position of the current window. (window.moveTo)

Args :
    x: the x-coordinate in pixels to set the window position
    y: the y-coordinate in pixels to set the window position
Usage :
    driver.set_window_position(0,0)

  • 定义:

  • Defination:

    def set_window_position(self, x, y, windowHandle='current'):
        if self.w3c:
            if windowHandle != 'current':
            warnings.warn("Only 'current' window is supported for W3C compatibile browsers.")
            return self.set_window_rect(x=int(x), y=int(y))
        else:
            self.execute(Command.SET_WINDOW_POSITION,
                 {
                     'x': int(x),
                     'y': int(y),
                     'windowHandle': windowHandle
                 })
    

  • 总而言之,window_position耦合到与浏览器有关的窗口句柄,并且只能由 webdriver 实例处理.

    So to summarize, window_position is coupled to the window handle pertaining to the browser and can be handled by webdriver instance only.

    此功能也无法通过以下方式处理:

    This functionality can't be handled either through :

    • firefox_profile -> set_preference(key, value): Sets the preference that we want in the profile.
    • firefox.options -> set_preference(name, value): Sets a preference.

    这篇关于如何使用FirefoxProfile或FirefoxOptions通过Selenium设置Firefox浏览器的窗口位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-06 03:51