简体   繁体   English

如何使用 Selenium webdriver 解决屏幕尺寸非常小的问题

[英]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 .问题是 Windows 在从Jenkins运行时默认为非常小的屏幕尺寸(我假设为 800x600)。 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.然后,如果被测网站不支持如此小的分辨率且不重叠 UI 元素,则浏览器将无法对不再可见的项目进行一些测试。 How can we solve this?我们如何解决这个问题?

It would be best maximize your window as soon as you instantiate your web driver instance.最好在实例化 Web 驱动程序实例后立即最大化您的窗口。

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:我不知道您的代码的设置,但请在您创建要使用的 Web 驱动程序实例后尝试添加以下行:

Java爪哇

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

C# C#

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

Python Python

driver.maximize_window()

Ruby红宝石

@driver.manage.window.maximize

The above may not work in Chrome - if this is the case, please use:以上在 Chrome 中可能不起作用 - 如果是这种情况,请使用:

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:根据@Ardesco 和@Fenio 的评论-您还可以使用以下方法设置特定尺寸:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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