问题
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();
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/34882935/is-that-good-to-use-driver-manage-window-maximize-in-selenium-for-every-ti