第三个支付脚本报错session not created exception,出现脚本只执行一半就卡死情况

3/3/2017来源:C/C++教程人气:1234

Chrome下运行脚本,报错:

  elenium.common.exceptions.WebDriverException: Message: session not created exception

  from disconnected: received Inspector.detached event   (Session info: chrome=52.0.2743.6)   (Driver info: chromedriver=2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961),platform=Windows NT 6.1 SP1 x86_64)

脚本:【

# coding=utf-8
from selenium import webdriver
from time import sleep

driver =webdriver.Chrome()
driver.get("https://m.edmbuy.com/")

driver.find_element_by_xpath("/html/body/footer/a[4]").click()
sleep(3)driver.find_element_by_xpath("//*[@class='peoname']").click()
driver.find_element_by_id("global_frm_mobile").send_keys("18124682152")
driver.find_element_by_id("global_frm_passwd").send_keys("123456")
driver.find_element_by_id("login_btn").click()
sleep(3)driver.find_element_by_xpath("//*[@class='boxsiz cart']").click()
driver.find_element_by_xpath("/html/body/div[2]/b").click()
driver.find_element_by_xpath("//*[@id='cart_t_btn']").click()
driver.find_element_by_xpath("//*[@id='btn-wxpay']").click()
sleep(3)
driver.close()

程序执行前半步骤都ok,后半步骤不能执行并一直报错“找不到定位对象或是提示对象定位错误的问题”,找了很久都没发现问题的原因是什么,后来在步骤中间添加了一个sleep延迟解决了这个问题(程序执行有时候会出现卡机,或者运行被占用{Ctrl+alt+delete关闭Chromedriver.exe},未完成加载等可能情况,需要做延迟 等待程序完成加载再继续执行)