【问题标题】:Message: selenium.common.exceptions.TimeoutException消息:selenium.common.exceptions.TimeoutException
【发布时间】:2021-03-25 06:34:37
【问题描述】:

我是 python 新手,目前正在处理结帐页面上的自动提交。我知道该元素在 iframe 内,因此我改用了 By.Xpath,"//iframe

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 15).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='newCard']")))
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='newCard' and @id='newCard']"))).send_keys("4242424242424242")

但我仍然在下面收到此错误。

Traceback (most recent call last):
  File "C:\Users\USER\Desktop\Python Scripts\Nike_autologin_autofill_v2.py", line 44, in <module>
    WebDriverWait(driver, 15).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='newCard']")))
  File "C:\Users\USER\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

【问题讨论】:

  • 你能添加你的 iframe 的 HTML 标签吗?

标签: python selenium iframe webdriverwait timeoutexception


【解决方案1】:

"iframe.newCard" CSS-selector 表示 具有 类名 'newCard'

的 iframe 节点

您需要指定@class 而不是@id。尝试替换

"//iframe[@id='newCard']"

"//iframe[@class='newCard']"

【讨论】:

  • 我已将其替换为@class,但仍然无法正常工作。
  • @Ben 你在同一行得到 TimeOutException 吗?共享跟踪日志
猜你喜欢
  • 1970-01-01
  • 2021-04-20
  • 1970-01-01
  • 2021-06-02
  • 1970-01-01
  • 1970-01-01
  • 2021-10-15
  • 1970-01-01
  • 2021-03-24
相关资源
最近更新 更多