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.
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
).