Wait for page load in Selenium

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

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

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 08:05

    You can use wait. there are basically 2 types of wait in selenium

    • Implicit wait
    • Explicit wait

    - Implicit wait

    This is very simple please see syntax below:

    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    

    - Explicit wait

    Explicitly wait or conditional wait in this wait until given condition is occurred.

    WebDriverWait wait = new WebDriverWait(driver, 40);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
    

    You can use other properties like visblityOf(), visblityOfElement()

提交回复
热议问题