from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait
driver = webdriver.Chrome()
driver.get('website')
customerid_form_elements = driver.find_elements(By.CSS_SELECTOR, "input[aria-labelledby='i1']")
for form_element in customerid_form_elements:
form_element.send_keys("test")
charge_input = input("Charge Amount: ")
form_charge = driver.find_elements(By.CSS_SELECTOR, "input[aria-labelledby='i5']")
for charge in form_charge:
charge.send_keys(charge_input)
user_input = input("Card & CVV '6969696969696969 666': ")
input_list = user_input.split()
text_field_1 = driver.find_element(By.CSS_SELECTOR, "input[aria-labelledby='i9']")
text_field_2 = driver.find_element(By.CSS_SELECTOR, "input[aria-labelledby='i21']")
text_field_1.send_keys(input_list[0])
text_field_2.send_keys(input_list[1])
last_four_field = driver.find_element(By.CSS_SELECTOR, "input[aria-labelledby='i25']")
card_number = input_list[0]
last_four = card_number[-4:]
last_four_field.send_keys(last_four)
expiration_date = input("Expiration date (MM): ")
dropdown_element = driver.find_element(By.XPATH, "//div[@jsname='LgbsSe']")
dropdown_element.click()
options = driver.find_elements(By.XPATH, "//div[@jsaction and starts-with(@data-value, '[01]')]")
for option in options:
if option.get_attribute("data-value") == expiration_date:
option.click()
break
一切都运行良好,直到它必须点击我从下拉菜单输入的数据值。不能使用选择器,因为它是一个div类。相当混乱。看到图片的jsaction值我试图点击基于我的输入。
HTML pic
1条答案
按热度按时间m2xkgtsf1#
我已经修改了你的一些代码,请尝试:
对于“Customer ID”字段,定位器只有一个匹配项,因此您需要使用
find_elements
和for
循环,您可以使用以下代码: