[英]Start firefox unmaximized with selenium in python
I am using Selenium in Python with Firefox.我在 Python 中使用 Selenium 和 Firefox。 Firefox is always started in maximized mode, which does not work very well with my tiling window manager Awesome on Linux. Firefox 总是以最大化模式启动,这在 Linux 上与我的平铺窗口管理器 Awesome 运行得不太好。
How can I prevent Firefox being opened in maximized mode with Selenium and Python?如何防止使用 Selenium 和 Python 以最大化模式打开 Firefox? Or how can I unmaximize a window?或者如何取消最大化窗口?
MWE: MWE:
#!/usr/bin/python
from selenium import webdriver
driver = webdriver.Firefox()
That opens Firefox in maximized mode on my setup.这会在我的设置中以最大化模式打开 Firefox。 My regular Firefox doesn't open in maximized mode.我的常规 Firefox 无法以最大化模式打开。
I know the function driver.window_maximize()
which apparently doesn't unmaximize the window.我知道函数driver.window_maximize()
显然不会driver.window_maximize()
窗口。
Use an instance of firefox.options
to add the argument --window-size
to open Firefox in any size as follows:使用firefox.options
的实例添加参数--window-size
以打开任意大小的 Firefox,如下所示:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("--window-size=900,600")
driver = webdriver.Firefox(options=options, executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get('http://google.com/')
You can find a couple of detailed discussions in:您可以在以下位置找到一些详细的讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.