Reputation: 12568
I am using Python Selenium to find an element within the following HTML...
<div id="results">
<h1>Results</h1>
<p>These Are The Results</p>
<ul>
<li>Result 1</li>
<li>Result 2</li>
<li>Result 3</li>
<li>Result 4</li>
</ul>
</div>
result = driver.find_element_by_css_selector("#results").text
This works correctly but the data it returns does not include the HTML tags, is there a way I can make it return the HTML tags as well as the data with the #results div?
Upvotes: 0
Views: 2717
Reputation: 5127
In order to get HTML, you have to get attribute 'outerHTML' or 'innerHTML'. The outerHTML will include HTML of current element. See code below:
htmlText = driver.find_element_by_css_selector("#results").get_attribute("outerHTML")
Upvotes: 2