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

Viewed 2062

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?

2 Answers

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

html_text = element.find_element_by_xpath('..').get_attribute('outerHTML')
    String `val=driver.findElement(By.xpath("//input[@id='fileToUpload']")).getAttribute("outerHTML");`

For Java,Tested in 2020 with chrome 83 which gives Outter html value is

Related