今天研究了下ie、chrome、firefox瀏覽器執行腳本java
1.首先firefox下執行時,我是安裝在d盤了,因此要更改路徑web
//若是火狐瀏覽器沒有默認安裝在C盤,須要制定其路徑
System.setProperty("webdriver.firefox.bin", "D:/Softwareinstallation/huohu/firefox.exe");
WebDriver driver = new FirefoxDriver();chrome
2.在chrome下執行時,遇到了以下問題瀏覽器
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list安全
解決方法:google
下載chrome驅動插件,(包含ie驅動插件),代碼以下,還有問題的話,把路徑加到path變量中spa
http://yunpan.cn/c3kPMJTZDDLyv 訪問密碼 4dd5firefox
1 //谷歌瀏覽器 2 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Administrator\\Desktop\\testzidong\\selenium\\anzhuangbao\\chromedriver_win32\\chromedriver.exe"); 3 WebDriver driver=new ChromeDriver(); 4
3.在ie下運行時出現上面類型問題。解決方法同上插件
代碼以下:code
1 System.setProperty("webdriver.ie.driver", "C:\\Users\\Administrator\\Desktop\\testzidong\\selenium\\anzhuangbao\\IEDriverServer_x64_2.48.0\\IEDriverServer.exe"); 2 WebDriver driver = new InternetExplorerDriver();
可是在運行時又包了其餘錯。
解決方法以下: 把ie選項中的安全區域所有打上鉤