我需要使用 RemoteWebDriver 运行可移植 Firefox,但面临问题:
这是完美运行的本地运行代码:
FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(
new FirefoxBinary(
new File(System.getProperty("user.dir"),
"/tools/FirefoxPortable/FirefoxPortable.exe")),profile);
driver.get("http://google.com");
如何在本地服务器上运行它?像这样的东西:
WebDriver driver = new RemoteWebDriver(DesiredCapabilities.firefox());
driver.get("http://google.com");
最佳答案
如果您使用RemoteWebDriver
,有两种方法设置firefox
二进制文件,如下所示:
您需要将
FirefoxBinary
设置为DesiredCapativity
如下:FirefoxBinary bin = new FirefoxBinary( new File(System.getProperty("user.dir"), "/tools/FirefoxPortable/FirefoxPortable.exe")); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(FirefoxDriver.BINARY, bin); WebDriver driver = new RemoteWebDriver(capabilities); driver.get("http://google.com");
您需要使用
-Dwebdriver.firefox.bin
属性运行selenium-server-standalone-x.jar
,该属性将指向firefox
二进制路径为:java -jar selenium-server-standalone-x.jar -Dwebdriver.firefox.bin="path/to/firefox binary"
现在您可以使用
firefox
实例化RemoteWebDriver
如下:WebDriver driver = new RemoteWebDriver(DesiredCapabilities.firefox()); driver.get("http://google.com");
关于java - 远程运行可移植 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38892533/