java 每次调用浏览器时在 selenium 中使用 driver.manage().window().maximize() 是不是很好

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34882935/
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-11-02 23:30:12  来源:igfitidea点击:

Is that good to use driver.manage().window().maximize() in selenium for every time we invoke browser

javaseleniumselenium-webdriverautomationselenium-firefoxdriver

提问by Siva K Reddy C Shiva

We use driver.manage().window().maximize();to maximize the browser.

我们driver.manage().window().maximize();用来最大化浏览器。

I have seen few examples online that are using driver.manage().window().maximize()though it's not required to maximize the browser. (For Ex: gmail login)

我在网上看到的例子很少,driver.manage().window().maximize()虽然不需要最大化浏览器。(例如:gmail 登录)

Also I see on invoking browser using selenium it opens in maximized window only. Still I have to use this driver.manage().window().maximize();

我还看到使用 selenium 调用浏览器时它仅在最大化窗口中打开。我仍然必须使用这个driver.manage().window().maximize();

回答by Guy

Short answer: Yes.

简短的回答:是的。

Little longer answer: when selenium is interacting with the web page, like clicking on button or writing to text field, the interacted WebElementmust be visible, or you will get exception. If you think on performance calling one time to window().maximize()is much 'cheaper' (and much less prone to errors) than scrolling to the WebElementevery time.

稍微长一点的答案:当 selenium 与网页交互时,比如点击按钮或写入文本字段,交互WebElement必须是可见的,否则你会得到异常。如果您认为性能调用一次window().maximize()WebElement每次都滚动到更“便宜”(并且更不容易出错)。

You gave Gmail login as example, but usually you need to do more than just login in tests project.

您以 Gmail 登录为例,但通常您需要做的不仅仅是登录测试项目。

By the way

顺便一提

Also I see on invoking browser using selenium it opens in maximized window only

我还看到在使用 selenium 调用浏览器时,它仅在最大化窗口中打开

Is not true.

不是真的。

回答by pratapvaibhav19

It depends on your choice. If window is not maximized, probably You might not be able to find element on page. So if you need such element then it worth to maximize window.

这取决于您的选择。如果窗口未最大化,可能您可能无法在页面上找到元素。所以如果你需要这样的元素,那么最大化窗口是值得的。

回答by amitbobade

As [pratapvaibhav19] said, it's totally depends on your choice. There are different ways of doing this, you can open maximized Chrome windows. For Firefox and IE you can use driver.manage().window().maximize();. Alternatively you can open browser window as per your screen resolution OR in custom size.

正如 [pratapvaibhav19] 所说,这完全取决于您的选择。有多种方法可以做到这一点,您可以打开最大化的 Chrome 窗口。对于 Firefox 和 IE,您可以使用 driver.manage().window().maximize();。或者,您可以根据您的屏幕分辨率或自定义大小打开浏览器窗口。

回答by unickq

You don'thave to maximize the window. Selenium can interact with the browser in any screen resolution, because it doesn't use the mouse or keyboard like desktop automation tools.

不必最大化窗口。Selenium 可以在任何屏幕分辨率下与浏览器交互,因为它不像桌面自动化工具那样使用鼠标或键盘。

It's just easier to view web pages and take screenshots on bigger browser windows.

在更大的浏览器窗口上查看网页和截屏更容易。