Python 消息:selenium.common.exceptions.TimeoutException

Python 消息:selenium.common.exceptions.TimeoutException,python,selenium,iframe,webdriverwait,timeoutexception,Python,Selenium,Iframe,Webdriverwait,Timeoutexception,我是python新手,目前正在处理签出页面上的自动提交。我知道元素在iframe中,因此我使用了.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_s

我是python新手,目前正在处理签出页面上的自动提交。我知道元素在iframe中,因此我使用了.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: 
回溯(最近一次呼叫最后一次):
文件“C:\Users\USER\Desktop\Python Scripts\Nike\u autologin\u autofill\u v2.py”,第44行,在
WebDriverWait(driver,15).until(EC.frame\u to\u be\u available\u和\u switch\u to\u it((By.XPATH,//iframe[@id='newCard']))
文件“C:\Users\USER\AppData\Local\Programs\Python39\lib\site packages\selenium\webdriver\support\wait.py”,第80行,在
引发TimeoutException(消息、屏幕、堆栈跟踪)
selenium.common.Exception.TimeoutException:消息:
“iframe.newCard”
CSS选择器表示具有类名的iframe节点“newCard”

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

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

“iframe.newCard”
CSS选择器表示类名称为“newCard”的iframe节点

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

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


我已将其替换为@class,但仍然不起作用。@Ben您是否在同一行中获得了TimeOutException?共享跟踪日志我已将其替换为@class,但仍然不起作用。@Ben您是否在同一行中获得了TimeOutException?共享跟踪日志您是否可以添加iframe的HTML标记?是否可以添加iframe的HTML标记?