Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way of getting outerHTML of outerHTML of a web element using Selenium in Python?

I am using this for get a row in a table:

element = browser.find_element_by_xpath("//*[contains(text(),'Sample Text')]")
html_text = element.get_attribute('outerHTML')

this gives me <td>...</td> but I want <tr><td>...</td><td>...</td></tr>

How do I do this?

like image 901
dsauce Avatar asked Sep 11 '25 21:09

dsauce


1 Answers

If you want to get outerHTML of parent element, you can use below

html_text = element.find_element_by_xpath('..').get_attribute('outerHTML')
like image 51
Andersson Avatar answered Sep 14 '25 10:09

Andersson