selenium RC+JAVA 运行所遇到的问题

时间:2024-09-02 09:35:38

1.报错一

Failed to start new browser session: java.lang.RuntimeException: Firefox 3 could not be found in the path!
Please add the directory containing ''firefox.exe'' to your PATH environment.

原因:

  firefox没有安装在c盘(本人安装在d盘下),selenium找不到firefox路径。
解决过程:首先尝试将firefox.exe的路径放到系统环境变量path中,重新运行,错误依旧。
正确解决办法:在调用firefox处加上绝对路径(selenium("localhost", 4444, "*firefox D:\\Program Files\\Mozilla Firefox\\firefox.exe", "http://www.baidu.com"))

2. 报错二

  Firefox 无法在 chrome://src/content/TestRunner.html?auto=true&multiWindow=true&defaultLogLevel=info&baseUrl=http://localhost:8080/&resultsUrl=http://localhost:4445/selenium-server/postResults&test=http://localhost:4445/selenium-server/tests/login_suite.html 找到该文件。

请检查文件名的大小写或者其他输入错误。
    请检查文件是否已被移动,重命名或删除

原因:

  Firefox版本与selenium server版本不一致导致的。

  百度了下,原来是selenium的版本和firefox不兼容,需要升级selenium或者firefox。

  【Selenium】   -> 【FireFox】

  2.25.0        ->  18

  2.30.0        ->  19

  2.31.0        ->  20

  2.42.2        ->  29

  2.44.0        ->  33 (不支持31,2014/12/1) 升级selenium jar包,或者是升级firefox。

   PS:但是selenium-java-2.42.2版本和firefox 29.0.1版本兼容,如果升级到firefox 30+,则浏览器启动失败。可能是selenium还未同步升级,后面估计可以正常支持。切记,关掉forefox的升级功能,否则连本地Windows上的脚本都跑不起来,作者曾经为此还降级了forefox。 升级后,selenium脚本正常启动firefox。

  Firefox旧版本下载地址:

  Linux: https://download.mozilla.org/?product=firefox-17.0&os=Linux&lang=zh-CN

  Windows: https://download.mozilla.org/?product=firefox-17.0&os=win&lang=zh-CN