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

edited May 14, 2018 by eLiJha 107 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,650 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,510 points
227 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
813 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,290 points
1,372 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,420 points
1,192 views
0 votes
1 answer

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,090 points
566 views
0 votes
1 answer
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,130 points
895 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
559 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,650 points
91 views
0 votes
3 answers