我正在为www.kith.com编写一个bot,我已经过了卡号,当我使用最后10行代码(卡上的名称、过期日期、安全代码)时。。。我得到这个错误
“引发TimeoutException(消息、屏幕、堆栈跟踪)
TimeoutException'
在我添加webdriver wait之前,我得到的代码是init使用了3个参数,但给出了2个参数,或者类似的东西,我对编码比较陌生,所以这是一个挑战
code:
driver = webdriver.Chrome(executable_path=r'C:\webdrivers\Chromedriver.exe')
driver.get(str(url))
#size
driver.find_element_by_xpath('//div[@data-value="S"]').click()
#ATC
driver.find_element_by_xpath('//button[@class="btn product-form__add-to-cart"]').click()
time.sleep(6)
#checkout
driver.find_element_by_xpath('//button[@class="btn ajaxcart__checkout"]').click()
time.sleep(3)
#email
driver.find_element_by_xpath('//input[@placeholder="Email"]').send_keys('example@gmail.com')
#first
driver.find_element_by_xpath('//input[@placeholder="First name"]').send_keys('first')
#last
driver.find_element_by_xpath('//input[@placeholder="Last name"]').send_keys('last')
#address
driver.find_element_by_xpath('//input[@placeholder="Address"]').send_keys('address')
#city
driver.find_element_by_xpath('//input[@placeholder="City"]').send_keys('town')
#zip
driver.find_element_by_xpath('//input[@placeholder="ZIP code"]').send_keys('99999')
#phone number
driver.find_element_by_xpath('//input[@placeholder="Phone"]').send_keys('9999999999' + u'\ue007')
time.sleep(5)
#continue to payment
driver.find_element_by_xpath('//button[@type="submit"]').click()
time.sleep(8)
#card number
driver.switch_to.frame(driver.find_element_by_class_name("card-fields-iframe"))
driver.find_element_by_id("number").send_keys('1234')
driver.find_element_by_id("number").send_keys('1234')
driver.find_element_by_id("number").send_keys('1234')
driver.find_element_by_id("number").send_keys('1234')
#payment
Exception(TimeoutException)
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@title,'Name on card')]")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-current-field]"))).send_keys('john')
driver.switch_to.default_content()
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@title,'Expiration date')]")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-current-field]"))).send_keys('11/23')
driver.switch_to.default_content()
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[contains(@title,'Security code')]")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@data-current-field]"))).send_keys('123')
driver.switch_to.default_content()
任何建议对我都很重要。StackOverflow迄今为止帮了我很多忙。<;3
看起来您在切换帧时遇到了问题。请按照下面的代码行进行注释
您位于frame卡字段iframe中,现在如下所示
它将尝试在iframe的卡字段中搜索框架到期日期。接下来的两帧,依此类推。我不确定你的帧是否像这样层叠。如果卡片上的这些框架名称、有效期等彼此不在一起,请在执行操作后转到父框架,在父框架中隐藏所有这些名称
注意:我不确定您购买的是哪个国家。然而,我已经在我的位置(新加坡)做了,并能够点击以下代码付款。请参阅,新加坡的物体和框架与您的位置不同
删除此行
你的代码可以运行,你不需要添加这一行
您将使用
WebDriverWait(driver, 10)
给出超时参数10或者你希望的任何时间都是你的脚本等待的时间
相关问题 更多 >
编程相关推荐