I'm trying to write into "Security 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
我该如何解决?
答案 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