突然间,我所有的测试都停止了工作。我得到的错误信息是
java.lang.IllegalStateException: Unable to locate element by xpath for com.gargoylesoftware.htmlunit.TextPage@11d1aa6
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByXPath(HtmlUnitDriver.java:796)
at org.openqa.selenium.By$ByXPath.findElement(By.java:344)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1251)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1248)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:991)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1248)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:397)
在线指点
WebElement menu = driver.findElement(By.xpath("//a[starts-with(@href,'/index.html')]"));
我的驱动程序初始化
public class ExtendedHtmlUnitDriver extends HtmlUnitDriver {
public ExtendedHtmlUnitDriver(boolean enableJavascript) {
super(BrowserVersion.FIREFOX_10);
this.setJavascriptEnabled(enableJavascript);
this.getWebClient().setCssEnabled(false);
}
告诉我出了什么事!
重新启动计算机似乎可以解决此问题。