0 votes
1 view
in Devops and Agile by (19.8k points)

I'm using the Python bindings to run Selenium WebDriver.

from selenium import webdriver

wd = webdriver.Firefox()

 I know I can grab a web element like so...

elem = wd.find_element_by_css_selector('#my-id')

And I know I can get the full page source with...


 But is there any way to get the "element source"?

elem.source   # <-- returns the HTML as a string

The selenium web driver docs for Python are basically non-existent and I don't see anything in the code that seems to enable that functionality.

Any thoughts on the best way to access the HTML of an element (and its children)?


1 Answer

0 votes
by (63.4k points)

You can read the innerHTML attribute to get a source of the content of the element or outerHTML for source with the current element.













Tested and works with the ChromeDriver.

Hope this helps!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !