我如何对页面源进行明确的等待检查

时间:2019-05-21 01:37:51

标签: python selenium

这只是一个示例,但是我想在html源中的Hello显式等待时,如何使它工作?

if "Hello" in html_source:

WebDriverWait wait = new WebDriverWait(driver,10)
wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("foobar")))

1 个答案:

答案 0 :(得分:0)

From selenium documentation

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//*[text()='Hello']")))
    print(driver.page_source)
except:
    print("element could not be found within the 10 second timeout period")

如果您想获得更好的答案,建议您ask a better questionuse examples