如何在python中使用phantomjs和selenium webdriver设置窗口大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21899953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:49:46  来源:igfitidea点击:

How to set window size using phantomjs and selenium webdriver in python

pythonseleniumselenium-webdriverphantomjs

提问by user61629

I'm trying to get a full sized browser screenshot with phantomjs driven by python webdriver . right now my screenshot is measured at 927 x 870, I'd like to reset it. I have tried:

我正在尝试使用由 python webdriver 驱动的 phantomjs 获取全尺寸浏览器屏幕截图。现在我的屏幕截图是 927 x 870,我想重置它。我试过了:

driver.manage().window().setSize(new Dimension(1400,1000))

based on this source, but this is giving syntax errors.

基于此来源,但这会导致语法错误。

How can I do this?

我怎样才能做到这一点?

采纳答案by Yi Zeng

Because that's Java. Python's documentation is here.

因为那是Java。Python 的文档在这里

There's a method called set_window_size, which is defined here:

有一个方法叫做set_window_size,它在这里定义:

driver.set_window_size(1400,1000)

Further reading: How to get window size, resize or maximize window using Selenium WebDriver

进一步阅读: 如何使用 Selenium WebDriver 获取窗口大小、调整大小或最大化窗口

回答by joCs

For Java, the Dimension import has to be:

对于 Java,维度导入必须是:

import org.openqa.selenium.Dimension;

and it won't give syntax errors

它不会给出语法错误