【发布时间】:2013-09-30 17:55:49
【问题描述】:
我正在使用 Selenium 并在 Python 中编码。
在我提交 Javascript 表单后,页面会继续动态加载以获取结果。我基本上是在等待一个元素(一个特定的按钮链接)出现/完成加载,所以我可以点击它。我该怎么做?
【问题讨论】:
标签: python python-2.7 selenium selenium-webdriver
我正在使用 Selenium 并在 Python 中编码。
在我提交 Javascript 表单后,页面会继续动态加载以获取结果。我基本上是在等待一个元素(一个特定的按钮链接)出现/完成加载,所以我可以点击它。我该怎么做?
【问题讨论】:
标签: python python-2.7 selenium selenium-webdriver
您可以使用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?
【讨论】: