Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Below is my Selenium Webdriver script. When I run this script my website is opened but the popup window is also opened. How do I close this popup window so the script can continue? Take a look on screenshot also.

package com.angara;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class TestAngaraWeb {

   public static void main(String[]args){

      WebDriver driver = new FirefoxDriver();
      driver.get("http://www.angara.com");
      driver.findElement(By.xpath("/html/body/div[6]/div/div[2]/div/div/div/ul/li/a")).click();


   }
}

enter image description here

share|improve this question
1  
I can see no screenshot –  dzieciou Dec 7 '12 at 12:03
    
I attached a screenshot (it's a public website). As you can see from the screenshot, this is not a new browser window. –  user246 Dec 7 '12 at 15:05
3  
I think the solution is a simple as locating the "X" at the top of that "window" and clicking it. –  user246 Dec 7 '12 at 15:08
1  
Knowing common terminology for browser windows can help you in the future. Popup generally refers to a completely new browser window and is what people will assume if you use that term. This is an inline add or popover within your existing web page. –  Sam Woods Dec 8 '12 at 2:56

6 Answers 6

As user246 commented, you can write a method to locate the 'X' on the popup and click it if found. Then you can define a custom method to locate an element on the page, something like this (kind of pseudo code):

myFindElement(String xpath)
{
    try{
        driver.findElement(By.xpath(path))
    }
    catch (ElementNotFoundException e){
        if !closethepopup(){print ('Element not found')}
    }
    catch (GeneralException ge){
    }
}

Within your closethepopup() method, you can choose to add some logic to return false if the popup is not found

share|improve this answer

Try this

Driver.SwitchTo().frame("Fancybox-frame");

Driver.findElement("enter your xpath to close popup").click();

Driver.SwitchTo().defaultContent();

share|improve this answer

To close popup - first you need to check which one is the active window in your application (Popup or main window). If popup is active then you can use " driver.close();" OR if the main window is active (Focused), then you need to use window handler to close this popup.

share|improve this answer
WebDriver driver = new FirefoxDriver();
driver.get("http://www.angara.com/");
driver.findElement(By.xpath("//*[@id='popsubform']/a/img")).click();

Try this out... hope this will help you out..

share|improve this answer

driver.findElement(By.xpath("//*[@id="popsubform"]/a/img")).click();

This should look for the "X" on the pop up and close it.

share|improve this answer

enter image description here

how to use the same Xpath for to pop ups

enter image description here

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

    
While the screenshots are helpful, you really need to give more information in your answer. –  Kate Paulk Oct 29 at 11:00
    
I think this has potential to be a great answer if you could elaborate on it a bit more. Are we supposed to be following the XPath in your screenshot? –  corsiKa Nov 4 at 17:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.