Python中文
首页
教程
问答
标签
搜索
登录
注册
如何使用selenium webdriver处理超时异常错误
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<div> </div> <p>我正在为<a href="http://www.kith.com" rel="nofollow noreferrer">www.kith.com</a>编写一个bot,我已经过了卡号,当我使用最后10行代码(卡上的名称、过期日期、安全代码)时。。。我得到这个错误</p> <p>“引发TimeoutException(消息、屏幕、堆栈跟踪)</p> <p>TimeoutException'</p> <p>在我添加webdriver wait之前,我得到的代码是<strong>init</strong>使用了3个参数,但给出了2个参数,或者类似的东西,我对编码比较陌生,所以这是一个挑战</p> <pre><code> 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() </code></pre> <p>任何建议对我都很重要。StackOverflow迄今为止帮了我很多忙。<;3</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>删除此行</p> <pre><code>Exception(TimeoutException) </code></pre> <p>你的代码可以运行,你不需要添加这一行</p> <p>您将使用<code> WebDriverWait(driver, 10)</code>给出超时参数</p> <p>10或者你希望的任何时间都是你的脚本等待的时间</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
为什么我的神经网络模型的准确性不能在这个训练集上得到提高?
6 回答
为什么我的神经网络模型的权重变化不大?
5 回答
为什么我的神经网络的成本不断增加?
7 回答
为什么我的神经网络的输入pickle文件是19GB?
2 回答
为什么我的神经网络给属性错误?“非类型”对象没有属性“形状”
3 回答
为什么我的神经网络训练这么慢?
9 回答
为什么我的神经网络输出错误?
2 回答
为什么我的神经网络预测适用于MNIST手绘图像时是正确的,而适用于我自己的手绘图像时是不正确的?
6 回答
为什么我的神经网络验证精度比我的训练精度高,而且它们都是常数?
3 回答
为什么我的私人用户间聊天会显示在其他用户的聊天档案中?
7 回答
为什么我的积分的绝对误差估计值大于积分(使用scipy.integrate.nqad)?
7 回答
为什么我的积层回归器得分比它的组件差?
4 回答
为什么我的移动方法不起作用?
3 回答
为什么我的稀疏张量不能转换成张量
7 回答
为什么我的稀疏张量不能转换成张量?
1 回答
为什么我的程序“停止”了?
1 回答
为什么我的程序一直试图占用所有可用的CPU
4 回答
为什么我的程序不使用指定的代理
8 回答
为什么我的程序不工作(python帮助中的反向函数)?
4 回答
为什么我的程序不工作时,我使用多处理模块
4 回答