問題1:IE驅動位數問題,未安裝對應的IE,打不開IE瀏覽器(已解決20180323)
使用Selenium啟動IE瀏覽器的時候,報錯,報錯信息如下
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070002 ('系統找不到指定的文件。') for URL 'http://localhost:36608/' (WARNING: The server did not provide any stacktrace information)
單純看這個報錯信息,看不太明白,在網上搜尋答案無果,但是看到了增加打印日志的語句
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability("logLevel", "DEBUG"); driver = new InternetExplorerDriver(capabilities);
問題原因:通過查看DEBUG級別的日志,可以看到錯誤原因是因為找不到文件所以打不開IE,於是聯想到我的IE驅動是32位的,而我只安裝了64位的IE,沒有裝32位的IE瀏覽器,所以才會打不開。
解決方案:更換為64位的IE驅動,完美解決此問題。
附上驅動下載地址:下載IEDriver
問題2:打開https地址時,IE瀏覽器彈出提示窗口,導致程序無法繼續運行(已解決20180323)
selenium在打開地址"https://www.baidu.com/"時報錯
org.openqa.selenium.UnhandledAlertException: Modal dialog present: 是否只查看安全傳送的網頁內容?
問題原因:https安全協議導致ie瀏覽器彈窗(Modal dialog),阻止了程序運行
解決方案:1.將https改為http后不再彈出對話窗可以正常運行,但沒從根本解決問題
2.可以在彈出窗口之后插入一句代碼driver.switchTo().alert().accept(); 對彈出對話框進行處理,程序可以繼續運行
問題3:selenium打開chrome時,chromedriver.exe停止運行(已解決20180323)
程序在打開chrome瀏覽器時報錯
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
問題原因:chromedriver版本和chrome瀏覽器版本不兼容,詳見https://blog.csdn.net/huilan_same/article/details/51896672,列出了兼容的chromedriver和對應的chrome瀏覽器版本
解決方案:因為我的chrome瀏覽器是版本是56,更換chromedriver版本為2.28,解決問題