HtmlUnitDriver()不起作用

时间:2013-09-12 19:31:37

标签: java selenium htmlunit htmlunit-driver

我在Eclipse中设置了一个selenium项目。我能够让我的selenium项目与firefox驱动程序一起工作;但是,当我尝试使用HtmlUnitDriver时,我收到以下错误:

Exception in thread "main" net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: Exception: java.lang.RuntimeException: java.io.FileNotFoundException: \Settlement\static\css\WebDirect_1.css (The system cannot find the path specified)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:965)
at net.sourceforge.htmlunit.corejs.javascript.Context.reportRuntimeError(Context.java:1017)
at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet.loadStylesheet(CSSStyleSheet.java:279)
at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLLinkElement.getSheet(HTMLLinkElement.java:129)
at com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList.jsxFunction_item(StyleSheetList.java:126)
at com.gargoylesoftware.htmlunit.javascript.host.Window.jsxFunction_getComputedStyle(Window.java:1454)
at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.jsxGet_currentStyle(HTMLElement.java:208)
at com.gargoylesoftware.htmlunit.html.DomNode.isDisplayed(DomNode.java:683)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.getTextFromNode(HtmlUnitWebElement.java:572)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.getText(HtmlUnitWebElement.java:524)
at com.automation.selenium.HTMLToExcelExporter.extractParticipantID(HTMLToExcelExporter.java:753)
at com.automation.selenium.HTMLToExcelExporter.generateFileOutputPath(HTMLToExcelExporter.java:760)
at com.automation.selenium.HTMLToExcelExporter.initializeFileOutputStream(HTMLToExcelExporter.java:106)
at com.automation.selenium.MainClass.main(MainClass.java:38)

简而言之,我正在尝试执行以下代码:

WebDriver webDriver = new HtmlUnitDriver();
webDriver.get("Some web page");
WebElement element = webDriver.findElement(By.xpath("some xpath"));

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

错误很明显:

  

FileNotFoundException:\ Settlement \ static \ css \ WebDirect_1.css(系统找不到指定的路径)

在您的网络服务器中添加该文件即可。

现在,如果您正在尝试网络抓取,那么您无法解决这个问题。但是,您可以尝试通过在WebClientOption对象中将setThrowExceptionOnScriptError设置为false来防止丢失的文件引发异常。