Reputation: 1234
All of a sudden all my tests stopped working. Error message I get is
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)
Pointing on line
WebElement menu = driver.findElement(By.xpath("//a[starts-with(@href,'/index.html')]"));
My driver initialization
public class ExtendedHtmlUnitDriver extends HtmlUnitDriver {
public ExtendedHtmlUnitDriver(boolean enableJavascript) {
super(BrowserVersion.FIREFOX_10);
this.setJavascriptEnabled(enableJavascript);
this.getWebClient().setCssEnabled(false);
}
Tell me what's wrong!
Restarting computer seemed to fix this.
Upvotes: 1
Views: 1470
Reputation: 43474
DomNode
is the HtmlUnit class that provides the getByXPath(String)
method. If you're getting a TextPage
then you shouldn't use such a method as HtmlUnit couldn't recognize a DOM tree in the resulting page.
PS: I wonder how restarting your computer could have fixed this. Can you provide more detail?
Upvotes: 1