如何使用Java调整Selenium WebDriver中当前浏览器窗口的大小?
问题描述:
在执行Selenium自动化测试期间,我需要将浏览器的大小调整为300x400。如何使用Java调整Selenium WebDriver(又名Selenium 2)中的浏览器窗口大小?
I need to resize the browser as 300x400 during executing the Selenium automated tests. How can I resize the browser window in Selenium WebDriver (aka, Selenium 2) with Java?
[注意:它需要调整浏览器窗口的大小以测试响应式Web设计( RWD)]
[Note: It needs to resize the browser window for testing Responsive Web Design (RWD)]
答
您可以使用 driver.manage()获取对当前窗口的引用。窗口()
。而窗口
有一个 setSize()
方法,所以你可以尝试
You can get a reference to the current window with driver.manage().window()
. And the window
has a setSize()
method, so you could try
Dimension dimension = new Dimension(800, 600);
driver.manage().window().setSize(dimension)