Skip to content

Commit

Permalink
HtmlUnitDriver: fix findElementByXPath()
Browse files Browse the repository at this point in the history
XmlPage can be used as well to find by XPath

Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
  • Loading branch information
asashour authored and lukeis committed Jul 15, 2015
1 parent 87f28e8 commit c3bd000
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 5 additions & 5 deletions java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ protected void assertElementNotStale(DomElement element) {

// We need to walk the DOM to determine if the element is actually attached
DomNode parentElement = element;
while (parentElement != null && !(parentElement instanceof HtmlHtml)) {
while (parentElement != null && !(parentElement instanceof SgmlPage)) {
parentElement = parentElement.getParentNode();
}

Expand Down Expand Up @@ -1125,13 +1125,13 @@ public List<WebElement> findElementsByTagName(String using) {

@Override
public WebElement findElementByXPath(String selector) {
if (!(lastPage() instanceof HtmlPage)) {
if (!(lastPage() instanceof SgmlPage)) {
throw new IllegalStateException("Unable to locate element by xpath for " + lastPage());
}

Object node;
try {
node = ((HtmlPage) lastPage()).getFirstByXPath(selector);
node = ((SgmlPage) lastPage()).getFirstByXPath(selector);
} catch (Exception ex) {
// The xpath expression cannot be evaluated, so the expression is invalid
throw new InvalidSelectorException(
Expand All @@ -1141,8 +1141,8 @@ public WebElement findElementByXPath(String selector) {
if (node == null) {
throw new NoSuchElementException("Unable to locate a node using " + selector);
}
if (node instanceof HtmlElement) {
return newHtmlUnitWebElement((HtmlElement) node);
if (node instanceof DomElement) {
return newHtmlUnitWebElement((DomElement) node);
}
// The xpath expression selected something different than a WebElement.
// The selector is therefore invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ public void testShouldBeAbleToFindElementByXPathWithNamespace() {
}

@Ignore({IE, MARIONETTE, SAFARI, CHROME})
@NotYetImplemented(HTMLUNIT)
@Test
public void testShouldBeAbleToFindElementByXPathInXmlDocument() {
driver.get(pages.simpleXmlDocument);
Expand Down

0 comments on commit c3bd000

Please sign in to comment.