【发布时间】:2020-12-09 09:06:45
【问题描述】:
我正在为www.kith.com 编写一个机器人,我已经超过了卡号,当我使用最后 10 行代码时(卡上的姓名、到期时间、安全码)...我收到此错误,
"引发 TimeoutException(消息、屏幕、堆栈跟踪)
超时异常'
在我添加 webdriver 之前,等待我得到的代码是 init 使用 3 个参数,但给出了 2 个参数或类似的东西,我对编码比较陌生,所以这有点挑战。 p>
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 帮助了我很多。
【问题讨论】:
标签: python selenium exception automation webdriver