Handling Windows | Selenium Forum
20% Off Learning Discount Avail now

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()

P
Pinki Daga Reply on 19/10/2019

1) When you are saying , the driver is initialized, you mean to say "system.setProperty()", right? 

2) //below code means to instantiate google chrome browser driver =>  correct?


System.setProperty("webdriver.chrome.driver", "C:chromedriver.exe");

3) //below code means to Create Chrome Browser Driver => correct?


WebDriver driver = new ChromeDriver();

I am not able to distinguish between these 2 lines

S

Instructor

Support Team Reply on 21/10/2019

Whenever i say the driver is initialized, this means the below line

driver = new ChromeDriver();

or

driver = new FirefozDriver();

or the code like this.

P
Pinki Daga Reply on 21/10/2019

Thanks. So initializing, and not instantiating , right?

system . setProperty - simply providing path of driver exe, nothing else, right?

S

Instructor

Support Team Reply on 22/10/2019

System.setProperty() sets the seiver executable path only.

P
Pinki Daga Reply on 23/10/2019

ok thanks. we can close this query