Wait for page load in Selenium

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

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

30条回答
  •  感动是毒
    2020-11-22 08:00

    You can explicitly wait for an element to show up on the webpage before you can take any action (like element.click())

    driver.get("http://somedomain/url_that_delays_loading");
    WebElement myDynamicElement = (new WebDriverWait(driver, 10))
      .until(new ExpectedCondition(){
            @Override
            public WebElement apply(WebDriver d) {
            return d.findElement(By.id("myDynamicElement"));
    }});
    

    This is what I used for a similar scenario and it works fine.

提交回复
热议问题