我需要通过使用以下命令创建驱动程序来更改Firefox窗口的位置:
driver = webdriver.Firefox()
我知道在创建驱动程序之后可以更改窗口位置:
driver.set_window_position()
我无法找到使用Firefox配置文件或选项的方法:
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)
答案 0 :(得分:1)
您看对了。
set_window_position()
设置当前窗口的x
,y
位置。
实施:
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)
定义:
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 实例处理。
此功能也无法通过以下方式处理:
firefox_profile
-> set_preference(key, value)
:设置个人资料中的偏好设置。firefox.options
-> set_preference(name, value)
:设置首选项。