【问题标题】:After submitting form, how to wait for element to load before clicking on said element? (Selenium / Python)提交表单后,如何等待元素加载后再点击该元素? (硒/蟒蛇)
【发布时间】:2013-09-30 17:55:49
【问题描述】:

我正在使用 Selenium 并在 Python 中编码。

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

【问题讨论】:

    标签: python python-2.7 selenium selenium-webdriver


    【解决方案1】:

    您可以使用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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-06
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 2019-12-08
      • 1970-01-01
      • 2011-12-08
      相关资源
      最近更新 更多