java Selenium 3.0.1,新的FirefoxDriver+木偶卡在起始页上
我正在将Selenium应用程序从2.53迁移到3.0.1。首先,我想在一个小应用程序中测试它,只需启动浏览器并导航到特定页面
此外,我想为Firefox(51.0版,便携应用程序)使用一个自定义二进制文件
这是我的代码:
public class Selenium {
public static void main(String[] args) {
WebDriver driver = createFFDriver();
driver.navigate().to("http:....");
System.out.println("Finished");
}
public static WebDriver createFFDriver(){
System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,"foo/geckodriver64.exe");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("firefox_binary","foo/firefox.exe");
return new FirefoxDriver(capabilities);
}
}
浏览器实际上已打开,但被阻止
日志:
1486713046153 geckodriver INFO Listening on 127.0.0.1:12466
Feb 10, 2017 8:50:46 AM org.openqa.selenium.remote.ProtocolHandshake
createSession INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
1486713046731 mozprofile::profile INFO Using profile path foo\AppData\Local\Temp\rust_mozprofile.p25D0Gb1sBQm
1486713046752 geckodriver::marionette INFO Starting browser foo\firefox\51.0\FirefoxPortable.exe
1486713046782 geckodriver::marionette INFO Connecting to Marionette on localhost:52818
为什么Geckodriver在127.0.0.1:12466
上监听,但它试图连接到localhost:52818
上的木偶
编辑: 它卡在RemoteWebDriver startSession方法中:
Response response = this.execute("newSession", parameters);
# 1 楼答案
Firefox的便携版似乎无法与Gecko驱动程序配合使用
它与传统的Firefox(51.0.1)一样工作
# 2 楼答案
我用Selenium V3.0.1和Firefox 51.0.1(32位)尝试了你的代码,成功地访问了URL/其他web驱动程序功能/无阻塞
更新
WebDriver firefox; System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY,"pathtogeckodriver"); FirefoxProfile profile = new FirefoxProfile(); firefox = new FirefoxDriver( new FirefoxBinary( new File(System.getProperty("user.dir"), "\\FirefoxPortable\\FirefoxPortable.exe")), profile); driver.get("http://www.google.com");
这在可移植Firefox版本(51.0.1)中非常适用