Wait for page load in Selenium

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

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

30条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 08:10

    The best way I've seen is to utilize the stalenessOf ExpectedCondition, to wait for the old page to become stale.

    Example:

    WebDriver driver = new FirefoxDriver();
    WebDriverWait wait = new WebDriverWait(driver, 10);
    
    WebElement oldHtml = driver.findElement(By.tagName("html"));
    wait.until(ExpectedConditions.stalenessOf(oldHtml));
    

    It'll wait for ten seconds for the old HTML tag to become stale, and then throw an exception if it doesn't happen.

提交回复
热议问题