Matthias Lee
Matthias Lee

Reputation: 109

selenium ruby find parent of element

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?

Upvotes: 0

Views: 511

Answers (1)

Rajagopalan
Rajagopalan

Reputation: 6064

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")

Upvotes: 1

Related Questions