无法找到/打开Firefox二进制webdriver/robot框架
我的测试在java和fine中运行得很好。当使用Internet Explorer和Chrome通过机器人框架执行它们时,它们也运行得很好。但是,当我使用'new FirefoxDriver()‘通过火狐执行它们时,我收到以下错误:
DEBUG java.lang.ExceptionInInitializerError
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java: 81)
Caused by: java.lang.NullPointerException
org.openqa.selenium.firefox.FirefoxBinary.<clinit>(FirefoxBinary.java: 42)
... 183 more 在FirefoxBinary和FirefoxDriver类中,这些行对应于以下代码:
FirefoxBinary ln42-43
private static final String PATH_PREFIX = "/" +
FirefoxBinary.class.getPackage().getName().replace(".", "/") + "/";
and FirefoxDriver ln 80-82
public FirefoxDriver(FirefoxProfile profile) {
this(new FirefoxBinary(), profile);
} 我尝试在类路径、pythonpath (由robotframework使用)和path中设置Firefox二进制文件的路径。我还编写了以下几行代码,试图强制查找二进制文件:
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(FirefoxDriver.BINARY, "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");我尝试在两台计算机上执行测试,这两台计算机分别是我的工作计算机和家庭计算机。此外,我还尝试使用使用firefox.exe -p创建的火狐配置文件,也尝试通过在java代码中创建一个配置文件。我试过Firefox 6-8。不幸的是,这些方法都没有起作用。
我还在使用/已经使用过: Java 1.6 Selenium 2.9.0/2.13.0 Windows 7
我不确定这是否相关,但作为一种变通办法,我一直在尝试让Firefox通过远程浏览器运行。我一直在尝试以下代码:
rcc = new RemoteControlConfiguration();
rcc.setPort(4447);
rcc.setPortDriversShouldContact(4447);
rcc.setInteractive(true);
rcc.setSingleWindow(true);
rcc.setTimeoutInSeconds(30);
ss = new SeleniumServer(rcc);
ss.start();
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
cap.setBrowserName("firefox");
URL url = new URL ("http://www.google.com/");
driver = new RemoteWebDriver(url,cap);但是,当我运行上面的命令时,我得到了以下错误消息:
Exception in thread "main" org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.13.0', revision: '14794', time: '2011-11-18 17:49:47'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: Selenium2Driver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)有人知道如何解决我的两个问题吗?
任何帮助都会非常感谢,我觉得在这个问题上自动取款机非常卡住。在Internet Explorer已经支持…的情况下,花了两天时间尝试让Firefox正常工作。。感觉好像世界末日就要来了。
谢谢,詹姆斯
编辑:1
我可以使用selenium-server来运行Firefox。
发布于 2012-11-07 11:54:08
仅供参考,RemoteWebDriver的网址在上面的帖子中显示不正确。应该更像"localhost:4444/wd/hub";?有趣的是,我的Web Driver遇到了相反的问题,通过RemoteWebDriver启动火狐遇到了问题,但火狐通过原生FirefoxDriver运行得很好。IE在远程模式下工作正常。- David Dec 4 '11 4:51
谢谢,大卫!
发布于 2013-11-18 01:32:11
我不明白为什么你没有在你的远程网格config.json文件中配置你的火狐二进制文件?我就是这么做的。这样,您的DesiredCapabilities对象就不需要定义它了。提示可以在here中找到。
如果工作正常,JSON文件中的代码行可能如下所示:
"binary": "C:/Program Files/Mozilla Firefox/firefox.exe",我猜它不允许您从代码中动态设置二进制文件的位置,但也许您可以尝试这样做,以证明它是否应该作为故障排除步骤。
发布于 2014-01-03 13:44:06
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary(new File("C:\\path to firefox\\firefox.exe"));
driver = new FirefoxDriver(binary, profile);尝尝这个
https://stackoverflow.com/questions/8236947
复制相似问题