提交表单后,如何在点击所述元素之前等待元素加载?(Selenium/Python)

Inf*_*ion 3 python selenium python-2.7 selenium-webdriver

我在Python中使用Selenium和编码.

在我提交Javascript表单后,页面将继续动态加载结果.我基本上等待一个元素(一个特定的按钮链接)出现/完成加载,所以我可以点击它.我该怎么做呢?

eng*_*ree 11

你可以使用WebDriverWait,这里的文档,

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()
Run Code Online (Sandbox Code Playgroud)

另外,看一个类似的问题,如何让Selenium/Python等待用户登录才能继续运行?