如何使用Selenium和Python在信用卡号字段中输入日期? [英] How to enter date in the credit card number field using Selenium and Python?

查看:164
本文介绍了如何使用Selenium和Python在信用卡号字段中输入日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本来自动在Shopify网站上结帐.当我尝试填写要求提供信用卡的字段时,硒不允许我将密钥发送到该字段中,并说元素不可交互.我已经尝试单击它,但是仍然不能让我输入信息.有谁知道该怎么办?

I am trying to make a script to automatically checkout on a Shopify site. When I try to fill in the field that is asking for the credit card, selenium is not allowing me to send in the keys into the field and is saying that the element is not interactable. I've already tried clicking it, but it's still not letting me enter in the information. Does anyone know what to do?

driver.find_element_by_xpath('//div[@data-card-field-placeholder="Card number"]').click()
driver.find_element_by_xpath('//div[@data-card-field-placeholder="Card number"]').send_keys("1234")

URL: https://feature.com/4089909/checkouts/2f7c52e34622f0f301c0d4b5720ad80e?previous_step = shipping_method& step = payment_method

是我正在尝试对其进行测试的链接

is the link I am trying to test this out on

推荐答案

要访问该页面以提供信用卡详细信息,我们需要超越

To access the page to provide the credit card details we need to move beyond the CONTACT INFORMATION information page. Hence, couldn't access it directly.

信用卡号字段位于< iframe> 中.因此,要访问< iframe> 中的信用卡号字段,因此您必须:

Ideally Creditcard Number fields are with in an <iframe>. Hence to access the Creditcard Number field within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

引发 WebDriverWait 使所需的元素可点击.

您可以使用以下定位器策略:

使用 CSS_SELECTOR :

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe_css")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div[data-card-field-placeholder="Card number]"))).send_keys("1234")

  • 使用 XPATH :

    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"iframe_xpath")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@data-card-field-placeholder="Card number"]"))).send_keys("1234")
    

  • 注意:您必须添加以下导入:

  • Note : You have to add the following imports :

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

  • 您可以在以下位置找到一些相关的讨论:

    You can find a couple of relevant discussions in:

    您可以在以下位置找到几个相关的详细讨论:

    You can find a couple of relevant detailed discussions in:

    这篇关于如何使用Selenium和Python在信用卡号字段中输入日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆