I am looking for something like:
getElementByXpath(//html[1]/body[1]/div[1]).innerHTML
I need to get the innerHTML of elements using JS (to use that in Selenium WebDriver/Java, since WebDriver can't find it itself), but how?
I could use Id attribute, but not all elements have Id attribute.
[FIXED]
I am using jsoup to get it done in Java. That works for my needs. Thanks for the answers. :)
html
andbody
selectors are superfluous since a DIV must be a descendent of BODY (immediate or deeper) and BODY must be a child of HTML, so provided there are no other DIV elements in the document,//DIV[1]
should work (though I'm pretty rusty on XPath expressions). The DOM equivalent isdocument.getElementsByTagName('div')[1]
(or maybe0
). – RobG May 15 '12 at 10:29