消息:selenium.common.exceptions.TimeoutException

2024-06-26 01:47:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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: 

enter image description here


Tags: andtoidsupportbydriverseleniumbe
1条回答
网友
1楼 · 发布于 2024-06-26 01:47:27

"iframe.newCard"CSS选择器意味着具有类名的iframe节点“newCard”

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

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

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

相关问题 更多 >