How to get HTML source of WebElement in Selenium WebDriver using Python

from selenium import webdriver wd = webdriver.Firefox()

I know I can grab a webelement like so: elem = wd.find_element_by_css_selector(’#my-id’)

And I know I can get the full page source with… wd.page_source But is there a way to get the “element source”?

elem.source # ← returns the HTML as a string

The Selenium WebDriver documentation for Python are basically non-existent and I don’t see anything in the code that seems to enable that functionality.

What is the best way to access the HTML of an element (and its children)?

Python: element.get_attribute(‘innerHTML’)