如何使用FirefoxProfile或FirefoxOptions通过硒设置Firefox浏览器的窗口位置

问题描述 投票:0回答:1

我需要通过创建驱动程序来改变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) 
python selenium firefox geckodriver selenium-firefoxdriver
1个回答
1
投票

你看到它的权利。

set_window_position()

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

  • 执行: 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)
  • 定义: qazxsw POI

所以总结一下,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 }) 耦合到关于浏览器的窗口句柄,只能根据webdriver的情况下进行处理。

此功能无法通过处理两种:

  • window_position - > firefox_profile:设置,我们要在配置文件中的首选项。
  • set_preference(key, value) - > firefox.options:设置首选项。
© www.soinside.com 2019 - 2024. All rights reserved.