selenium頁面加載慢的問題


  selenium頁面加載慢的問題:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait #等待一個元素加載完成
from selenium.webdriver.support import expected_conditions as EC
import time


driver=webdriver.Chrome()  #配置參數
driver.get("https://www.baidu.com")
driver.implicitly_wait(10)   #控制操作的時間,在10秒之內,如果元素出現,就繼續執行,元素沒有出現最多10秒

#driver:調用瀏覽器; 15:設置15秒超時 ; 0.5:每0.5秒檢測一下;  until() : 一直等到
#根據ID來查找,ID為 kw   只有出現kw才操作   (By.ID,"kw")為一個元組
#ID可以換成其它想要查找的元素
#最多等15秒,必須等到這個元素的出現
elem=WebDriverWait(driver,15,0.5).until(EC.presence_of_element_located((By.ID,"kw"))) #節約時間,網頁出現這個元素再操作

elem.send_keys("selenium")
time.sleep(10)
driver.close()

 


免責聲明!

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



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