Wait for page load in Selenium

后端 未结 30 2762
攒了一身酷
攒了一身酷 2020-11-22 07:12

How do you make Selenium 2.0 wait for the page to load?

30条回答
  •  轮回少年
    2020-11-22 08:06

    How to get Selenium to wait for page load after a click provides the following interesting approach:

    1. Store a reference to a WebElement from the old page.
    2. Click the link.
    3. Keep on invoking operations on the WebElement until StaleElementReferenceException is thrown.

    Sample code:

    WebElement link = ...;
    link.click();
    new WebDriverWait(webDriver, timeout).until((org.openqa.selenium.WebDriver input) ->
    {
        try
        {
            link.isDisplayed();
            return false;
        }
        catch (StaleElementReferenceException unused)
        {
            return true;
        }
    });
    

提交回复
热议问题