如何对页面sou进行显式等待检查

2024-04-25 08:41:42 发布

您现在位置:Python中文网/ 问答频道 /正文

这只是一个例子,但我想如果Hello在html源代码上显式等待,我该如何使它工作?你知道吗

if "Hello" in html_source:

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

Tags: insourcehellonewbyif源代码html
1条回答
网友
1楼 · 发布于 2024-04-25 08:41:42

From ^{} 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。你知道吗

相关问题 更多 >