Handling selenium webdriver popups

0 votes

I'm using Firefox driver for my selenium code written in c# winform. The code is below and I'm trying to get the handle of the popup that comes up on clicking "webtraffic_popup_start_button". This should ideally get the handle of the popup. But what i'm getting back is the handle of the current popup.

string current = driver.CurrentWindowHandle;
driver.FindElement(By.XPath("//*[@id='webtraffic_popup_start_button']")).Click();
Thread.Sleep(Sleep_Seconds);
popup = driver.CurrentWindowHandle;
Thread.Sleep(3000);
driver.SwitchTo().Window(current);
Thread.Sleep(1000);

Any help is much appreciated. Thank you. The popup looks like this.

May 14, 2018 in Selenium by eLiJha
• 760 points

edited May 14, 2018 by eLiJha 226 views

1 answer to this question.

0 votes

If you want to handle the most recently poped-up window after the click, then do this:

driver.SwitchTo().Window(driver.WindowHandles.ToList().Last());

If you want to switch between handle popups, or go to the original/ parent popup, then they are done like this:

// For new popup or window
driver.SwitchTo().Window(driver.WindowHandles.ToList().Last());
 // For the parent popup or window
driver.SwitchTo().Window(driver.WindowHandles.ToList().First());
//or
driver.SwitchTo().DefaultContent();
answered May 14, 2018 by king_kenny
• 3,710 points

Related Questions In Selenium

0 votes
1 answer

Handling Alerts Selenium Webdriver

You can use Explicit Wait from here https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits public ...READ MORE

answered Apr 9, 2018 in Selenium by Damon Salvatore
• 5,550 points
742 views
0 votes
1 answer

Handling JavaScript Alert window in Selenium WebDriver

You should try using waits for alerts ...READ MORE

answered Apr 10, 2018 in Selenium by ghost
• 1,790 points
1,316 views
0 votes
1 answer

Handling calendar popup using Selenium WebDriver

You are selecting wrongly your elements in ...READ MORE

answered Apr 17, 2018 in Selenium by Shubham
• 13,450 points
2,788 views
0 votes
1 answer

Handling print dialog in Selenium WebDriver

In Selenium WebDriver we are not able ...READ MORE

answered May 11, 2018 in Selenium by Meci Matt
• 9,460 points
3,296 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
3,752 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,736 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,890 points
2,726 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 2 in Selenium by Sri
• 2,970 points
3,078 views
0 votes
1 answer

Need some advise on the preferred element locators with Selenium WebDriver

Well let's not call it "Hierarchy". But, ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,710 points
230 views
+2 votes
3 answers

Selenium Webdriver + Java - Eclipse: java.lang.NoClassDefFoundError

I also faced this issue first time, ...READ MORE

answered Aug 28, 2019 in Selenium by Shraddha
21,585 views