1. 在瀏覽器中安裝擴展
?
2. 運行代碼時候,報錯
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home?
此時下載?chromedriver:CNPM Binaries Mirror
記得要與 Google瀏覽器版本適配。
關(guān)于環(huán)境配置參考此鏈接(win轉(zhuǎn)mac不適應(yīng)太痛苦了):
Mac 安裝chromedriver碰到的一系列問題問題_qq_29803291的博客-CSDN博客
安裝成功以后可以在 terminal 中運行 ? chromedriver --version ?查看是否成功
ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429})
?3. 在使用selenium 測試web頁面時,總會遇到頁面加載過慢從而導致程序報錯的問題:
elenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".st-agora-player-privilege-button"}
(Session info: chrome=90.0.4430.212)
解決辦法:
1. 強制等待
? ? ? ? time.sleep(4) #強制暫停程序
2.?隱性等待(implicitly_wait())
????????隱性等待設(shè)置了一個時間,在一段時間內(nèi)網(wǎng)頁是否加載完成,如果完成了,就進行下一步;在設(shè)置的時間內(nèi)沒有加載完成,則會報超時加載;
????????
? ? ? ?driver=webdriver.Chrome()
? ? ? ?driver.implicitly_wait(20) # 隱性等待,最長等30秒
3. 顯性等待
? 參考: ? ? ??python selenium 等待頁面加載_python selenium 三種等待方式詳解(實戰(zhàn)常用)_weixin_39998462的博客-CSDN博客
4. 設(shè)置瀏覽器為手機模式:文章來源:http://www.zghlxwxcb.cn/news/detail-402795.html
參考:python之selenium設(shè)置瀏覽器為手機模式(開發(fā)者模式)_好度的博客-CSDN博客文章來源地址http://www.zghlxwxcb.cn/news/detail-402795.html
到了這里,關(guān)于自動化測試- selenium的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!