How to resize current browser window in Selenium WebDriver with Java?

假如想象 提交于 2019-12-03 05:41:42
NilsH

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)

For Responsive Design it's better if you don't use fixed data, in this case screen resolution - users need most often (cause it's much less prone to errors) :

_driver.manage().window().maximize();

or

_driver.manage().window().fullScreen();
Neha

We can also use Chrome capability to resize the window.

ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=800,480");

DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!