WebDriver启动各大浏览器问题整理
Chrome
-
chrome浏览器驱动问题
使用Chrome做测试时,报了如下错误:The path to the driver executable must be set by the webdirver.chrome.driver system properity
解决方案:
设置Chrome驱动文件的路径(xxx–>驱动文件的相对路径)System.setProperty("webdriver.chrome.driver", "xxx");
-
Chrome与ChromeDriver版本对照说明(Chrome V70以下)
ChromeDriver 版本 支持的 Chrome 版本 v2.41 v67-69 v2.40 v66-68 v2.39 v66-68 v2.38 v65-67 v2.37 v64-66 v2.36 v65-67 v2.35 v62-64 v2.34 v61-63 v2.33 v60-62 v2.32 v59-61 v2.31 v58-60 v2.30 v58-60 v2.29 v56-58 Chrome V70版本以上按照版本对应文件夹即可
chrome浏览器各版本下载 http://www.chromedownloads.net/chrome64win/
禁止谷歌浏览器更新参考 https://blog.csdn.net/qq_42253278/article/details/111402748
Firefox
-
Firefox安装路径问题
firefox火狐浏览器去完成自动化测试时,代码报了如下错误:Cannot find firefox binary in PATH. mark sure firefox is installed
错误原因:
firefox安装在其它路径,不是默认的安装路径
解决办法:
指定firefox可执行文件路径:webdriver.firefox.bin
代码设置:#D:\\Program Files\\Mozilla Firefox\\firefox.exe为firefox可执行文件路径 System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
-
selenium Firefox驱动问题
使用firefox火狐浏览器去完成自动化测试时,代码报了如下错误:The path to the driver executable must be set by the webdriver.gecko.driver system properity
错误原因:
缺少火狐浏览器驱动包。如果selenium版本是3.x + 的,需要使用驱动包
解决办法:
往项目中添加火狐驱动包,并加载驱动的配置。至于该驱动版本适配的浏览器和selenium版本在驱动的change log里有说明(如:使用selenium 3.5.1+firefox 56)
代码设置:System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver.exe");
-
Firefox与geckodriver对应版本说明
geckodriver版本 Firefox版本 0.15 v 48+ 0.16 v 52 0.17 v 52 0.18 v 53 Change Log https://github.com/mozilla/geckodriver/blob/release/CHANGES.md
Firefox各版本下载地址 http://ftp.mozilla.org/pub/firefox/releases/(建议跟我保持一致,用57版本的firefox浏览器)
Firefox驱动镜像网址 https://npm.taobao.org/mirrors/geckodriver/
InternetExplorer
IE浏览器的驱动跟着Selenium版本走即可,比如当前项目使用的Selenium是V3.141.59,那么去Selenium的镜像网址下载对应版本的IEDriverServer驱动即可(建议使用32位的)
https://npm.taobao.org/mirrors/selenium
- IE浏览器驱动问题
使用IE浏览器去完成自动化测试时,代码报了如下错误:
错误总结:The path to the driver executable must be set by the webdriver.ie.driver system property
缺少IE浏览器驱动包
解决办法:
往项目中添加IE驱动包,并加载驱动的配置。
下载地址 http://www.seleniumhq.org/download/System.setProperty("webdriver.ie.driver", "src/test/resources/IEDriverServer.exe");
IE驱动版本与Selenium版本保持相同即可
http://selenium-release.storage.googleapis.com/index.html - IE浏览器保护模式问题
使用IE浏览器去完成自动化测试时,代码报了如下错误:
解决方法1:Protected Mode Settings are not the same for all zones
浏览器设置(但是换一台电脑就不适用了)
打开IE浏览器->工具->安全->全部勾选启用保护模式
解决方法2:
忽略浏览器保护模式的设置InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
代码://取消IE安全设置(忽略IE的Protected Mode的设置) DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
- IE浏览器缩放设置
使用IE浏览器去完成自动化测试时,代码报了如下错误:
错误总结:Browser zoom level was set to 125%.It should be set to 100%
浏览器缩放级别设置不对导致的(点工具栏页面->缩放设置)
解决办法:
忽略此设置:InternetExplorerDriver.IGNORE_ZOOM_SETTING
代码:DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
- IE浏览器window丢失问题
使用IE浏览器去完成自动化测试时,代码报了如下错误:
错误总结:unable to find element with id -- kw
不是因为没有设置等待时间,而是因为之前的window对象已经丢失
解决办法:
最快的解决办法是直接指定一个初始化页面
InternetExplorerDriver.INITIAL_BROWSER_URL
代码:DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.baidu.com");