我在Eclipse中设置了一个硒项目。我能够让我的硒项目与火狐驱动程序一起工作;但是,当我尝试使用 HtmlUnitDriver 时,我收到以下错误:
Exception in thread "main" net.sourceforge.htmlunit.corejs.javascript.EvaluatorException: Exception: java.lang.RuntimeException: java.io.FileNotFoundException: SettlementstaticcssWebDirect_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"));
任何帮助将不胜感激。
错误非常明显:
FileNotFoundException: \Settlement\static\css\WebDirect_1.css (系统找不到指定的路径)
将文件添加到您的 Web 服务器中,就是这样。
现在,如果您尝试进行网络抓取,则无法解决此问题。但是,您可以尝试通过在 WebClientOption 对象中将setThrowExceptionOnScriptError
设置为false
来防止丢失的文件引发异常。