Handling Windows | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos

Selenium Training Forum

Handling Windows

P
Pinki Daga Post on 08/10/2019

I have following code for windows handling -

1. If I want to check whether pop up is present or not, should I not put the logic after driver.get()? As per the video, the code is even before opening the webpage.

2. If a window gets opened in new tab, that also is a pop up?

public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "D:\\Webdrivers\\geckodriver-v0.24.0-win64\\geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "null");
WebDriver driver = new FirefoxDriver();

Set wind = driver.getWindowHandles();
System.out.println("Total windows: "+ wind.size())


driver.get("https://www.naukri.com");
wind = driver.getWindowHandles();

//To check if pop up present ot not
if (wind.size()>1) {
System.out.println("Pop up present");
}else {
System.out.println("No popups");
}


System.out.println("Total windows: "+ wind.size());

 

S

Instructor

Support Team Reply on 09/10/2019

Yes, each tab is considered as a separate popup window.

Additionally the code is correct.

driver.get("https://www.naukri.com");
wind = driver.getWindowHandles();

wind is populated after the page has been opened.

P
Pinki Daga Reply on 09/10/2019

Thanks for the response.

So we can get the count of additional windows only after driver.get()?

S

Instructor

Support Team Reply on 09/10/2019

We can get the count anytime after the driver is initialized and before the driver.quit()