Search code examples
javaseleniumselenium-webdriverjunitjunit4

How to find the whether the current using window is maximize or minimize in selenium 2 WebDriver?


Is there any way to find the currently used browser window is whether maximized or minimized in Selenium as I am using JUnit for make test script of automation.

Thanks,

Mohan Raj


Solution

  • You can follow the below logic

    org.openqa.selenium.Dimension  dm = driver.manage().window().getSize();
    
    int relativemaxheight = 1280; // put your screen resolution height
    int relativemaxwidth = 800;   // put your screen resolution width
    
    if(dm.height < relativemaxheight && dm.width < relativemaxwidth){
        System.out.println("minimized");
    }
    

    Apart from this you can set default maximize capabilities when creating driver. The code will look like

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