selenium2-java环境搭建 示例为chrome浏览器


首先,安装并配置JDK,安装eclipse,安装firefox和chrome。下载selenium语言的JAVA库文件,下载地址为,如果打不开,则需要翻墙; http://www.seleniumhq.org/download/
 
其次, 在eclipse中新建项目,在新建项目中将下载的selenium的所有以 .jar为后缀的文件导入项目;导入方式:右键项目名-->build path-->config build path-->java build path-->libraries-->add External jarars
 
然后,新建测试编写代码,开始运行;运行报错“”Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see  https://github.com/mozilla/geckodriver. The latest version can be downloaded from  https://github.com/mozilla/geckodriver/releases“”  因为是用的selenium3,所以需要在谷歌上下载驱动程序,下载地址 https://github.com/mozilla/geckodriver/releases/tag/v0.9.0,根据系统版本选择。解压后放到chrome的浏览器按照目录,并添加代码 System.setProperty("webdriver.chrome.marionette","C:\\Program Files (x86)\\Google\\Chrome\\Application\\geckodriver.exe");
 
 
运行结果,打开了浏览器并访问了正确的地址,就对了。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM