自动化测试- selenium

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浏览器版本适配。

关于环境配置参考此链接(win转mac不适应太痛苦了):

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())

        隐性等待设置了一个时间,在一段时间内网页是否加载完成,如果完成了,就进行下一步;在设置的时间内没有加载完成,则会报超时加载;

        

       driver=webdriver.Chrome()

       driver.implicitly_wait(20) # 隐性等待,最长等30秒

3. 显性等待

  参考:       python selenium 等待页面加载_python selenium 三种等待方式详解(实战常用)_weixin_39998462的博客-CSDN博客

4. 设置浏览器为手机模式:

参考:python之selenium设置浏览器为手机模式(开发者模式)_好度的博客-CSDN博客

猜你喜欢

转载自blog.csdn.net/yn20000227/article/details/126708932