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
• 770 points

edited May 14, 2018 by eLiJha 773 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,980 points
1,654 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
2,145 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,490 points
4,181 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
7,578 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,500 points
12,717 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,611 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,910 points
6,685 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 3, 2020 in Selenium by Sri
• 3,190 points
7,553 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
1,004 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
68,268 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP