Nick Realdini
Nick Realdini

Reputation: 77

Selenium IDE - Waiting for modal to disappear

How can I have Selenium IDE to wait for a modal layer to disappear before continuing to fill in the form and click on the button to move to the next step?

Upvotes: 1

Views: 5732

Answers (3)

Polina Spilka
Polina Spilka

Reputation: 31

This answer of Happy Bird (thanks a lot, have no access to up-vote yet) is working perfect in java for me as well and saved me a lot of time:

WebDriverWait wait = new WebDriverWait(getWebDriver(), 10);
wait.until(new ExpectedCondition<Boolean>() {
                    public Boolean apply(WebDriver driver) {                
                        return  getWebDriver().findElements(By.xpath("//div[contains(@class, 'modal-backdrop')]")).size() == 0;                   
                    }
                });

Upvotes: 2

Happy Bird
Happy Bird

Reputation: 1142

c# code

I had the same problem and this code is working for me since 6+ months, no more crash.

 public static void WaitForModal(this IWebDriver driver)
    {
        wait.Until<IWebDriver>((d) =>
        {
            if (driver.FindElements(By.ClassName("modal-backdrop")).Count == 0)
            {
                return driver;
            }
            return null;
        });
    }

It waits until it finds no more IWebElement that have a class of "modal-backdrop".

Upvotes: 2

DMart
DMart

Reputation: 2461

This seems perfect use case for either waitForElementNotPresent or WaitForElementNotVisible. Both of those will wait up until the default timeout for the elements to no longer be seen on the screen.

You could use Pause but that is almost NEVER the right answer because waitFor's will only take the amount of time needed up to the timeout. Pause will ALWAYS wait the full time, which is bad.

Upvotes: 1

Related Questions