das
das

Reputation: 63

Python Selenium get element content

If I do

match = driver.find_element_by_class_name("match")
print(match.text)

I only get the text in the element.

<class id="match">
    This is a text. This is displayed with .text
    <p align="center"><a href="www.stackoverflow.com"></p>
    The above is not displayed with .text
</class>

What to do when I also want the html in the element, not only the text?

Upvotes: 0

Views: 1474

Answers (1)

Denis Koreyba
Denis Koreyba

Reputation: 3718

If you want to get HTML code inside an element but not including the code of the element you should use this:

element.get_attribute('innerHTML');

If you want to get HTML code inside an element including the code of the element then you should use this:

element.get_attribute('outerHTML')

Upvotes: 2

Related Questions