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

后端 未结 3 1539
无人及你
无人及你 2021-02-07 07:10

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?

相关标签:
3条回答
  • 2021-02-07 07:51

    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();
    
    0 讨论(0)
  • 2021-02-07 07:56

    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)
    
    0 讨论(0)
  • 2021-02-07 07:57

    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);
    
    0 讨论(0)
提交回复
热议问题