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
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);
Using document.hidden will return True/False
Code: var js = (IJavaScriptExecutor)driver; var isMin= js.ExecuteScript("return document.hidden").ToString();
var js = (IJavaScriptExecutor)driver; var isMin= js.ExecuteScript("return document.hidden").ToString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.