如何在Selenium WebDriver中设置浏览器的宽度和高度? [英] How do I set browser width and height in Selenium WebDriver?

查看:670
本文介绍了如何在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)

这篇关于如何在Selenium WebDriver中设置浏览器的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆