简体   繁体   中英

How to fix the issue with very small screen size with Selenium webdriver

We just ran into a problem in our test automation infrastructure. The problem is that Windows defaults to a very small screen size (I assume 800x600) while running from Jenkins . Then if the website under test doesn't support such a small resolution without overlapping UI elements, the browser will fail some tests for items that are no longer visible. How can we solve this?

It would be best maximize your window as soon as you instantiate your web driver instance.

I don't know the setup of your code but please try adding the following line after you've created an instance of the web driver you wish to use:

Java

driver.manage().window().maximize();

C#

_driver.Manage().Window.Maximize();

Python

driver.maximize_window()

Ruby

@driver.manage.window.maximize

The above may not work in Chrome - if this is the case, please use:

ChromeOptions options = new ChromeOptions();
options.addArgument("--start-maximized");
driver = new ChromeDriver(options);

As per @Ardesco & @Fenio comments - you can also set a specific dimension using:

driver.manage().window().setSize(new Dimension(1920,1080));
driver.manage().window().fullscreen()

在您的驱动程序设置中,您可以使用C#的以下内容更改浏览器窗口大小

driver.Manage().Window.Size = new System.Drawing.Size(width: 1600, height: 1200);

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