簡體   English   中英

消息:selenium.common.exceptions.TimeoutException

[英]Message: selenium.common.exceptions.TimeoutException

我是 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.newCard" CSS 選擇器表示iframe 節點, class 名稱為“newCard”

您需要指定@class而不是@id 嘗試更換

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM