新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python等待方式的介紹
1、強(qiáng)制等待,導(dǎo)入time模塊,使用time.sleep即可。

創(chuàng)新互聯(lián)公司專注于修水網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供修水營銷型網(wǎng)站建設(shè),修水網(wǎng)站制作、修水網(wǎng)頁設(shè)計(jì)、修水網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務(wù),打造修水網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供修水網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
diver.get("https://www.baidu.com")
diver.find_element_by_xpath('//div[@id="u1"]//a[@name="tj_login"]').click()
time.sleep(2)
diver.find_element_by_xpath('//p[@class="tang-pass-footerBarULogin pass-link"]').click()
time.sleep(3)2、隱性等待,設(shè)置超時(shí)時(shí)長,如果加載時(shí)間超過10s,就直接報(bào)超時(shí),如果在10s內(nèi)加載完成,就去進(jìn)行下一步的操作。
from selenium import webdriver
#打開一個(gè)會(huì)話
diver = webdriver.Chrome()
#全局等待方式
diver.implicitly_wait(10)#等待10s
#全屏
diver.maximize_window()
#訪問百度鏈接
diver.get("https://www.baidu.com")
diver.find_element_by_xpath('//div[@id="u1"]//a[@name="tj_login"]').click()
diver.find_element_by_xpath('//p[@class="tang-pass-footerBarULogin pass-link"]').click()
diver.quit()#關(guān)閉會(huì)話3、顯性等待,等待被設(shè)置的元素可見。
from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC
以上就是python等待方式的介紹,希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
分享題目:創(chuàng)新互聯(lián)Python教程:python等待方式的介紹
文章分享:http://m.5511xx.com/article/cdoesoc.html


咨詢
建站咨詢
