Home > Software design >  selenium ruby find parent of element
selenium ruby find parent of element

Time:02-12

How do I get the parent element of any given element in selenium with ruby?

Let's say I have this:

<ul>
<li id="a"></li>
</ul>

and I can get the li with driver.find_element(id: "a"), how do I get the parent of that element that I found?

CodePudding user response:

This code will help you to find the parent element

element = driver.find_element(id: "a")
element.find_element(xpath: "./..")

This code will help you to verify the element html

p element.find_element(xpath: "./..").attribute("innerHTML")
  • Related