简体   繁体   中英

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

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

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)

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

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 WebElement must 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 WebElement every time.

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

By the way

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

Is not true.

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.

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.

You don't have 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM