selenium.common.exceptions.WebDriverException: Message: TypeError: rect is undefined


今天寫python測試腳本遇到這個問題,問題出現的背景是:登錄需要操作滑動條,圖片吻合后才驗證通過。系統是固定十張圖片,隨機產生;當驗證通過后一直報錯selenium.common.exceptions.WebDriverException: Message: TypeError: rect is undefined

貼上代碼,因為啥幫其他朋友測試,代碼比較簡易,沒時間整理,將就一下;如果有朋友知道解決辦法,麻煩留言下,不勝感激!

from selenium import webdriver from selenium.webdriver import ActionChains import time from selenium.common.exceptions import NoSuchElementException def is_element_present(driver, how, what): try: driver.find_element(by=how, value=what) except NoSuchElementException: return False return True driver = webdriver.Firefox() driver.get('https://www.duoduodaizhang.com/login') time.sleep(2) phone = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div/div[2]/div[2]/div/div[1]/input") phone.click() phone.send_keys('1897XXXXXXXX') password = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div/div[2]/div[2]/div/div[2]/input") password.click() password.send_keys('XXXXXXX') button = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div/div[2]/div[2]/div/div[3]/button") button.click() time.sleep(2) huadong = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[1]/div[2]/div[3]/div/div/div[2]/div/div[2]/div") action_chains = ActionChains(driver) for i in range(0,10): action_chains.drag_and_drop_by_offset(huadong,200,0).perform() if is_element_present(driver,'xpath',"/html/body/div[1]/div/div/div[1]/div/div[1]/ul/li[5]/a[2]")==False: continue
    if is_element_present(driver, 'xpath', "/html/body/div[1]/div/div/div[1]/div/div[1]/ul/li[5]/a[2]") == True: print('success') break

 不穩定的解決辦法:

for i in range(0,10):
    action_chains.drag_and_drop_by_offset(huadong,200,0).perform()
time.sleep(10)
強制休眠十秒,有一定機會成功!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM