3

Given the following html:

<div>
    <h4>some text</h4>
    <div>
        <ul></ul>
        <div></div>
        <p></p>
    </div>
</div>

These two xpaths find 1 node each:

//h4[contains(text(), 'some text')]/following-sibling::div/ul
//h4[contains(text(), 'some text')]/following-sibling::div/p

But this one returns 0 finds.

//h4[contains(text(), 'some text')]/following-sibling::div/div

Why doesn't the third xpath also return 1 find?

danger mouse
  • 1,457
  • 1
  • 18
  • 31
  • 2
    Where/How did you run the XPath? The third XPath returned 1 result for me, as expected : http://xpatheval.apphb.com/p_klroKSS – har07 Aug 27 '16 at 04:42
  • @har07. I hadn't know about that website, thanks. I've just run a check on the selenium WebDriver that I was using. I had been using an HtmlUnitDriver but when I changed this to a FirefoxDriver, the div element was found. I'm baffled. – danger mouse Aug 27 '16 at 04:58

1 Answers1

0

When I disabled javascript for the webpage that I was looking at, the HTML of the page changed. This solved the issue for me. Thanks to @Sebastian Zartner for this:

How can I get Firebug to match HtmlUnitDriver's pageSource report?

Community
  • 1
  • 1
danger mouse
  • 1,457
  • 1
  • 18
  • 31