无法使用Selenium Python将文本添加到IFrame中的输入type =“ tel”

时间:2019-12-30 15:37:56

标签: python selenium selenium-webdriver input web-scraping

HTML

I'm trying to write into "Security Code"

EDIT HTML CODE

我试图写这个:

CVXPATH = '//input[@type="tel"]' cv=driver.find_element_by_xpath(CVXPATH) cv.send_keys("000")

但是我有这个错误:

line 242, in check_response 
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

我该如何解决?

1 个答案:

答案 0 :(得分:1)

该元素位于iframe内部,您需要首先切换到iframe才能在输入字段中发送值。

引出WebDriverWait()并等待frame_to_be_available_and_switch_to_it()并跟随CSS selctor.

引出WebDriverWait()并等待element_to_be_clickable()并跟随XPATH

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,'iframe.credit-card-iframe-cvv')))
cv=WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//input[@id="cvNumber" and @type="tel"]')))
cv.send_keys("000")

您需要导入以下库。

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By