我正在使用此代码为我的HtmlUnitDriver设置功能:
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setJavascriptEnabled(true);
String browsername = getBrowser();
Platform platform = getPlatform();
System.out.println(browsername + " , " + platform.name());
caps.setBrowserName(browsername);
caps.setPlatform(platform);
HtmlUnitDriver driver = new HtmlUnitDriver(caps);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Capabilities caps2 = driver.getCapabilities();
System.out.println(caps2.getBrowserName() + " , " + caps2.getPlatform());
但我得到了这个输出:
opera , XP
htmlunit , WIN8_1
我错过了什么?
答案 0 :(得分:0)
尝试使用:
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setBrowserName(<browser_name>);
capabilities.setPlatform(<platform>);
capabilities.setVersion(<version>);
driver = new HtmlUnitDriver(capabilities);
希望它能奏效。
答案 1 :(得分:0)
我设法用这段代码解决了这个问题:
HtmlUnitDriver driver = new HtmlUnitDriver(new BrowserVersion(
"Firefox", "5.0 (Windows)", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0", 66));