Firefox
1. Firefox路徑問題
firefox火狐瀏覽器去完成自動化測試時,代碼報了如下錯誤:
Cannot find firefox binary in PATH. mark sure firefox is installed
錯誤原因:
firefox安裝在其它路徑,不是默認的安裝路徑
解決辦法:
指定firefox可執行文件路徑:webdriver.firefox.bin
代碼設置:
System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
2. selenium 3.x Firefox驅動問題
使用selenium3.x+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");
3. selenium與驅動版本匹配問題
使用selenium2.x版本+firefox去完成自動化測試時,代碼報了如下錯誤:
Unable to connect to host 127.0.0.1 on port 7055 after 45000ms
錯誤總結:
firefox瀏覽器版本和selenium版本不適配。
解決辦法:
建議降級火狐版本到47以下(比如:selenium 2.53.0+firefox 46)
4.selenium for firefox說明
selenium 2.x
selenium 2.x中自動集成了firefox驅動。
因此只須selenium 版本與firefox瀏覽器版本對應即可
selenium版本 | Firefox瀏覽器 |
---|---|
2.25.0 | v 18 |
2.30.0 | v 19 |
2.31.0 | v 20 |
2.42.2 | v 29 |
2.44.0 | v 33 (不支持31) |
2.52.0 | v 45.0 |
2.53.0 | v 46.0 |
2.53.1 | v 47.0.1 |
selenium 3.x
selenium,geckodriver,firefox 對應版本說明:
selenium版本 | geckodriver版本 | Firefox版本 |
---|---|---|
3.3 | 0.15 | v 48+ |
3.4 | 0.16 | v 52 |
3.4 | 0.17 | v 52 |
3.4 | 0.18 | v 53 |
3.5 | 0.19 | v 55 |
3.11 | 0.21 | v 57 |
- 從selenium 3.0.0開始就要求firefox為48及以上版本
- selenium 3.x使用的java版本為jdk 1.8
- selenium 3.x使用geckodriver作為firefox瀏覽器的驅動的替代
4、Firefox自動化相關工具鏈接
Change log https://raw.githubusercontent.com/SeleniumHQ/selenium/master/java/CHANGELOG
Firefox驅動https://github.com/mozilla/geckodriver/releases/
Firefox各版本 http://ftp.mozilla.org/pub/firefox/releases/
Firefox驅動 鏡像 https://npm.taobao.org/mirrors/geckodriver/
InternetExplorer
1. IE瀏覽器驅動問題
使用IE瀏覽器去完成自動化測試時,代碼報了如下錯誤:
The path to the driver executable must be set by the webdriver.ie.driver system property
錯誤總結:
缺少IE瀏覽器驅動包
解決辦法:
往項目中添加IE驅動包,並加載驅動的配置。
System.setProperty("webdriver.ie.driver", "src/test/resources/IEDriverServer.exe");
下載地址 http://www.seleniumhq.org/download/
建議下載版本:3.7.0
http://selenium-release.storage.googleapis.com/index.html?path=3.7/
IE驅動版本與Selenium版本保持相同即可
http://selenium-release.storage.googleapis.com/index.html
2. IE瀏覽器保護模式問題
使用IE瀏覽器去完成自動化測試時,代碼報了如下錯誤:
Protected Mode Settings are not the same for all zones
解決方法1:
瀏覽器設置(但是換一台電腦就不適用了)
打開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);
3. 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);
4. 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");
Chrome
1. chrome瀏覽器驅動路徑
使用Chrome做測試時,報了如下錯誤:
The path to the driver executable must be set by the webdirver.chrome.driver system properity
解決方案:
系統設置Chrome驅動文件的路徑
System.setProperty("webdriver.chrome.driver", "xxx");
2. chrome瀏覽器與chromeDriver匹配問題
使用chrome瀏覽器去完成自動化測試時,chrome瀏覽器停止運行
chromedriver.exe 已停止工作
錯誤總結:
chrome瀏覽器版本過高,雖然根據官網上的信息,2.33的chrome驅動支持60-62的谷歌。但是60根本不行
解決辦法:
降級chrome
3.Chrome與ChromeDriver版本對照表
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瀏覽器各版本
http://www.chromedownloads.net/chrome64win/
禁止谷歌瀏覽器更新
https://jingyan.baidu.com/article/76a7e409f2137afc3b6e15be.html
ChromeDriver 鏡像 http://npm.taobao.org/mirrors/chromedriver
Selenium 鏡像 http://npm.taobao.org/mirrors/selenium
JDK版本問題
使用3.x的selenium來完成自動化測試時,代碼報了如下錯誤:
Exception in thread "main" java.lang.UnsupportedClassVersionError:
錯誤總結:
3.x的selenium需要1.8的jdk,可能jdk版本過低
解決辦法:
降級selenium版本,或提高jdk的版本為1.8