0

When I click on a button on a page, a popup is displayed. This is not a windows popup. It is the application popup.. The popup I get in my application is similar to the one i have shown in the image with a X button. now How do I move the driver control to the popup and then click on the close button available on the popup and then move back my control back to the original page..

I have to do this using Selenium WebDriver and C#.

popup sample

2
  • 1
    Its a simple HTML, you need to find that element and press on close span or what is that. Commented Dec 25, 2013 at 13:02
  • oh.. i thought it should be handled like it is a new window.. anywasy.. will check and let u know if this worls Commented Dec 25, 2013 at 14:31

4 Answers 4

4

You need to do the following...

  • Loop through the windows and find the desired window
  • Switch to the windows
  • Find the button in the current window and click the same

Here is the sample code in C#

foreach (string handle in browser.WindowHandles) 
        {
            IWebDriver popup = driver.SwitchTo().Window(handle);

            if (popup.Title.Contains("popup title")) 
            {
              break;
            }
        }

IWebElement closeButton = driver.FindElement(By.Id("closeButton"));
closeButton.Click();
Sign up to request clarification or add additional context in comments.

1 Comment

The method works with a normal WebDriver like Chrome however it does not work for PhantomJS because WindowHandles throws an exception. I am using PhantomJS because I want to run my code from a process that does not have access to the desktop.
0

The new pop message too have an id or class name..
First get the class name or id of that pop up and the go for the xpath(may be we will find class name) of the close button and click on it.

Comments

0

The example you have shown is not a popup, but a simple DHTML window. To access the X of the example you have provided, you could use: driver.findElementBy(By.id("profile-tooltip-closebtn")).click().

Comments

0

You can try

driver.switchTo().frame(0);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.