【问题标题】:raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message引发 TimeoutException(消息,屏幕,堆栈跟踪) selenium.common.exceptions.TimeoutException:消息
【发布时间】:2021-04-26 12:19:56
【问题描述】:

当我尝试访问 flickr 中的登录页面时出现此错误 "引发 TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message"

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")

driver.get("https://www.flickr.com/")
driver.maximize_window()
wait = WebDriverWait (driver, 10)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//a[@id='yui_3_16_0_1_1619317268956_93511']")))
element.click()

【问题讨论】:

  • 尝试将超时时间从 10 提高到 20 或 30。更新我们如何为您工作。

标签: python selenium


【解决方案1】:

//a[@id='yui_3_16_0_1_1619317268956_93511']xpath 定位的元素未显示在https://www.flickr.com/ 主页上。
你应该改用//a[contains(@href,'signin')]

【讨论】:

  • 登录按钮
【解决方案2】:

如果您的目标是 login 按钮,请使用下面的 css 选择器:

element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='signin']")))

但如果你还想使用 xpath,建议@Prophet 是对的。

但请注意 css 选择器比 xpath 更快。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    • 2022-10-13
    • 1970-01-01
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    • 2015-04-09
    相关资源
    最近更新 更多