DoubtClear
DoubtClear

Reputation: 149

Wait for pop up window to close in selenium webdriver

Is there any command to wait for the popup to close.nActually my project is like on home page popup will appear and after choosing city pop gets close. Then I am able to click on sign in button. But when i run the script, before closing the pop up my next command which is click on sign in button are executing. So test script getting fail. When I used sleep (10000),then my script is working fine. But every time i don't want to use sleep,

Enter image description here

Please help me with your answers

Thanks

Upvotes: 0

Views: 10582

Answers (2)

Florent B.
Florent B.

Reputation: 42518

I would wait for the popup to be hidden :

WebDriverWait wait = new WebDriverWait(driver, 5000); // 5 seconds timeout
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("popup locator")));

Upvotes: 2

Pankaj Kumar Katiyar
Pankaj Kumar Katiyar

Reputation: 1494

One way to loop over and over rather than a fixed wait:

    WebDriver driver = new FirefoxDriver();

    //Accept the expected alert 
    driver.switchTo().alert().accept();

    //Wait dynamically to disappear 
    int i=0;
    while(i<15)
    {
        try{
            driver.switchTo().alert();
            Thread.sleep(2000);
        }catch(NoAlertPresentException a){
            break;
        }
        catch (Exception e) {
        }
        i++;
    }

Upvotes: 1

Related Questions