Get HTML of element not text


I have an xpath that correctly locates an element. How do I store the HTML (outerhtml) of the element to a variable. storeText only works if an element contains text and as far as I can see sourceExtract does not work with an xpath result.


Can I ask why you need the outerHTML?


Of course you may. I want to parse the element further. I do a lot of XQuery stuff so that’s how I approach these things.

To explain by example, I solved my problem by going the full selenium route. Python snippet as follows:

for entry in driver.find_elements_by_class_name('news-blocks'):
    category = entry.find_element_by_xpath('./h3').text
    speaker = entry.find_element_by_xpath('.//a[1]').text
    qnum = entry.find_element_by_xpath('.//a[2]').text