python自動化腳本示例支付:Chrome腳本報錯或出現腳本只執行一半就卡死情況

1.ChromeDriver版本和Chrome版本不兼容時,易出現運行報錯(更換對應匹配的版本)

2.頁面加載緩慢,出現執行一半就卡死情況(添加頁面加載等待sleep)

在Chrome下運行腳本,報錯(版本不兼容):  selenium.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},未完成加載等可能情況,需要做延遲 等待程序完成加載再繼續執行)

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章