如何使用Selenium WebDriver处理超时异常错误

问题描述

我正在为www.kith.com的机器人编写代码,我已经越过了卡号,并且当我使用最后10行代码(卡上的名称,有效期,安全代码)...出现此错误,

“引发TimeoutException(消息,屏幕,堆栈跟踪)

TimeoutException'

在我添加webdriver之前,请等待我得到的代码是 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('[email protected]')
        
        #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,'Expiration date')]")))
        WebDriverWait(driver,"//input[@data-current-field]"))).send_keys('11/23')
        driver.switch_to.default_content()
    
        WebDriverWait(driver,'Security code')]")))
        WebDriverWait(driver,"//input[@data-current-field]"))).send_keys('123')
        driver.switch_to.default_content()

任何建议对我来说都非常重要。到目前为止,StackOverflow已经帮助了我很多。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)