0

我在 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"));

任何帮助将不胜感激。

4

1 回答 1

0

错误很明显:

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

将文件添加到您的 Web 服务器中,就是这样。

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

于 2013-09-13T20:36:46.890 回答