问题描述
我正在尝试将Firefox驱动程序用于 Splinter ,以测试一些响应式设计.
I am trying to use the Firefox driver for Splinter to test some responsive design.
自然,这需要我调整浏览器窗口的大小.在文档中,我根本找不到有关浏览器大小调整的任何信息.
Naturally, this requires me to resize the browser window. I can't find anything at all about browser resizing in the documentation.
我该怎么做?
from splinter import Browser
with Browser() as browser:
# How do I set the browser size?
推荐答案
只需执行以下操作:
browser.driver.set_window_size(640, 480)
Splinter API似乎不直接支持此功能-或至少目前还不支持.通用 API文档以及每个特定浏览器驱动程序的文档,目前都未提及与窗口大小有关的任何内容).但是,一个看似未记录的功能是您可以通过其.driver
属性访问Splinter Webdriver实例的基础Selenium Webdriver实例:
The Splinter API doesn't seem to directly support this - or at least not yet. The generic API docs, as well as the docs for each specific browser's driver, currently make no mention of anything related to window size). However, a seemingly undocumented feature is that you're able to access the underlying Selenium webdriver instance of a Splinter webdriver instance through its .driver
property:
>>> from splinter import Browser
>>> browser = Browser()
>>> browser
<splinter.driver.webdriver.firefox.WebDriver object at 0x7fac66d93a10>
>>> browser.driver
<selenium.webdriver.firefox.webdriver.WebDriver object at 0x1fbf3d0>
这使我们能够使用Splinter API中没有包装器的所有Selenium功能,例如使用 set_window_size
方法.
This allows us to use any Selenium features that don't have wrappers in the Splinter API, like resizing the browser with the set_window_size
method.
这篇关于使用Splinter操纵浏览器(窗口)的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!