我正在使用Selenium和Python编码。
在我提交Javascript表单后,页面会继续动态加载结果。我基本上等待一个元素(一个特定的按钮链接)出现/完成加载,所以我可以点击它。我该怎么做呢?
答案 0 :(得分:11)
您可以使用WebDriverWait
,文档here,
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
ff = webdriver.Firefox()
ff.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(ff, 10).until(EC.presence_of_element_located((By.ID, "myDynamicElement")))
finally:
ff.quit()
另外,请看一个类似的问题How can I make Selenium/Python wait for the user to login before continuing to run?