简体   繁体   English

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

[英]How to set window position of Firefox browser through Selenium using FirefoxProfile or FirefoxOptions

I need to change the position of the Firefox window by creating the driver with:我需要通过使用以下命令创建驱动程序来更改 Firefox 窗口的位置:

driver = webdriver.Firefox()

I know it's possible to change the window position after the driver was created:我知道可以在创建驱动程序后更改窗口位置:

driver.set_window_position()

I can't find out how to do it using Firefox profile or options:我无法找到如何使用 Firefox 配置文件或选项进行操作:

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

or或者

options = Options()
options.some_optins = my_options

and finally:最后:

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

You saw it right.你没看错。

set_window_position()设置窗口位置()

set_window_position() sets the x , y position of the current window. set_window_position()设置当前窗口的x , y位置。

  • Implementation:执行:

     set_window_position(x, y, windowHandle='current') Sets the x,y position of the current window. (window.moveTo) Arguments : 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)
  • Definition:定义:

     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 })

So to summarize, window_position is coupled to the window handle pertaining to the browser and can be handled by webdriver instance only.总而言之, window_position耦合到属于浏览器的窗口句柄,并且只能由webdriver实例处理。

This functionality can't be handled either through:无法通过以下方式处理此功能:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 FirefoxOptions() 使用 Selenium/Python 放大/缩小 Firefox - How to zoom in/out in Firefox with Selenium/Python using FirefoxOptions() 如何通过Selenium和Python加载现有的FirefoxProfile - How to load a existing FirefoxProfile through Selenium and Python selenium没有在FirefoxProfile中设置downloaddir - selenium doesn't set downloaddir in FirefoxProfile 在 python Selenium/Firefox 中缩放浏览器窗口 - Zoom browser window in python Selenium/Firefox 如何使用 GeckoDriver 和 Selenium 到 ZA7F5F35426B927411FC9231B56382173 启动使用默认 Firefox 到 68.9.0esr 的 Tor 浏览器 9.5 - How to initiate a Tor Browser 9.5 which uses the default Firefox to 68.9.0esr using GeckoDriver and Selenium through Python 如何使用Selenium在PhantomJS中设置浏览器首选项 - How to set browser preference in PhantomJS using Selenium FirefoxProfile 与 Selenium 的私有模式 - FirefoxProfile with private mode for Selenium 如果 firefoxbinary 设置为 webdriver.Firefox(firefox_profile=profile, firefox_binary=binary),则 firefoxprofile 不起作用 - firefoxprofile not working if firefoxbinary is set as webdriver.Firefox(firefox_profile=profile, firefox_binary=binary) Cannot download PDF file in to the specified directory using selenium with python in Firefox browser, pdf file opens in browser window itself - Cannot download PDF file in to the specified directory using selenium with python in Firefox browser, pdf file opens in browser window itself 如何使用python的Selenium WebDriver在浏览器上打开一个新的window? - How to open a new window on a browser using Selenium WebDriver for python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM