【问题标题】:Python Selenium WebDriverWait issuePython Selenium WebDriverWait 问题
【发布时间】:2021-06-10 05:49:01
【问题描述】:

我正在尝试使用 WebDriverWait 来检查是否可以看到预期的仪表板 url 已加载,并且我还检查了是否存在强制徽标。我有下面的相关代码,

if WebDriverWait (driver, 30).until(EC.url_to_be(<expected_dashboard_url>) and driver.find_elements_by_id(<logo_id>):
    print("Successful")

我看到仪表板 URL 已正确加载到浏览器上,页面上也有预期的强制性徽标,但在我的控制台上我没有看到“成功”消息,因为它一直在等待并导致 TimeoutException。

注意:所有必要的导入都已完成,并且 webdriver 已正确实例化。

【问题讨论】:

  • 令人困惑的部分是,如果我尝试运行脚本 5 次,1 次我看到成功,其余 4 次我看到 TimeoutException,即使页面加载正确。

标签: python python-3.x selenium-webdriver webdriverwait chrome-web-driver


【解决方案1】:

如果我对问题的理解正确,你可以试试这个;

browser.get("url")
delay = 5
try:
    element = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.ID, 'id')))
except TimeoutException:
    print "not loaded"

我之前遇到过这个问题,并通过此链接中的解决方案解决了这个问题。如果这不起作用,您可以看看;

Wait until page is loaded with Selenium WebDriver for Python

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多