4

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?

3
  • 1
    Can you share HTML for the same? Commented Nov 22, 2017 at 19:12
  • 1
    Try //tr[contains(.,'Sample Text')] or //tr[td[contains(text(),'Sample Text')]] Commented Nov 22, 2017 at 19:13
  • You need to share the relevant HTML along with the outerHTML which you are trying to retrieve. Commented Nov 23, 2017 at 8:37

2 Answers 2

6

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

html_text = element.find_element_by_xpath('..').get_attribute('outerHTML')
Sign up to request clarification or add additional context in comments.

Comments

0
    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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.