如何在Selenium WebDriver中设置浏览器的宽度和高度?

如何在Selenium WebDriver中设置浏览器的宽度和高度?

问题描述:

我正在使用Selenium WebDriver for Python. 我想用特定的宽度和高度实例化浏览器.到目前为止,我能得到的最接近的是:

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: is there a way to set width / height at instantiation?

第二季度:参考文档在哪里列出了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)