今天研究了下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选项中的安全区域所有打上钩