selenium等待元素出現和代碼拋出異常繼續執行


1.隱式等待:

(1)全局的設定

  (2)后面所有的選擇元素的代碼都不需要單獨的指定周期性等待了

(3)driver.imlicitly_wait(10)

2.顯示等待:

(1)為一個操作頁面專門指定的時間

 (2) from selenium.webdriver.support.ui import WebDriverWait

           from selenium.webdriver.support import expected_conditions as EC

           from selenium.webdriver.common.by import By

           ele = WebDriverWait(driver,60)

           until(EC.presence_of_element_located((By.ID,'username')))

3.拋出異常繼續執行:

try:

      ele = driver.find_element_by_id('')

      print()

except:

       print('exception happend')


免責聲明!

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



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