问题描述
我在 Python 中使用 Selenium WebDriver.我想用特定的宽度和高度实例化浏览器.到目前为止,我能得到的最接近的是:
I'm using Selenium WebDriver for Python.I want instantiate the browser with a specific width and height. So far the closest I can get is:
driver = webdriver.Firefox()
driver.set_window_size(1080,800)
哪个有效,但在创建后设置浏览器大小,我希望它在实例化时设置.我猜有一种方法:
Which works, but sets the browser size after it is created, and I want it set at instantiation. I'm guessing there is an approach along the lines of:
profile = webdriver.FirefoxProfile();
profile.set_preference(foo, 1080)
driver = webdriver.Firefox(profile)
但我不知道 foo
是什么,而且我不知道文档在哪里.
But I don't know what foo
would be, and I can't figure out where the docs are.
Q1:有没有办法在实例化时设置宽度/高度?
Q1: is there a way to set width / height at instantiation?
问题 2: 列出 profile.set_preference
可用的所有键的参考文档在哪里?
Q2: Where are the reference docs listing all keys usable by profile.set_preference
?
推荐答案
这是我在 Python 中使用 Selenium 2.48.0 的方法:
Here is how I do it in Python with Selenium 2.48.0:
from selenium.webdriver import Firefox
driver = Firefox()
driver.set_window_position(0, 0)
driver.set_window_size(1024, 768)
这篇关于如何在 Selenium WebDriver 中设置浏览器的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!