# How to use WebExecute to retrieve WebElementObject HTML?

I know that I can use WebExecute to retrieve WebElementObject text, as in this example:

StartWebSession["Chrome"]
WebExecute["OpenPage"->"https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population"]
table = First@WebExecute["LocateElements"->"XPath"->"//*[@id=\"mw-content-text\"]/div/table"]
WebExecute["ElementText"->table]


And that I can retrieve the complete page HTML:

html = WebExecute["JavascriptExecute"->"return document.documentElement.outerHTML;"]


The question is: How can I get WebElementObject table data as HTML instead of text?

I explored some WebUnit functions, but without success.

COMPLEMENT

You can convert your HTML to data using:

ImportString[getAttribute[table, "innerHTML"],  {"HTML", "Data"}]


Had to dig a bit, but since it's just using the W3C WebDriver stuff you can do it by hand since WebExecute doesn't seem to expose all the requests:

getWebElementPropertyURL[el_, prop_] :=
URLBuild@
ReplacePart[
URLParse[el["URL"]],
"Path" -> {"session", el["SessionID"], "element", el["ElementId"],
"property",
prop
}
];
getWebElementProperty[el_, prop_] :=
Import[getWebElementPropertyURL[el, prop], "RawJSON"]["value"]

getWebElementProperty[table, "innerHTML"]

"#cite_note-218\">[197]</a></sup>
</td></tr>
</tbody><tfoot><tr>
<th></th>

• Cool! This answer is another option to get element properties using WebUnit. – Murta Mar 14 '20 at 11:54