Selenium get the parent of an element
You might run a in a situation when you selected an Element and you need to get it’s Parent . We can do this using xpath . So if you already did a request to get the element , this is how to get parent of an element.
If you already selected an element and want to get its parent, you can call find(:xpath, '..')
on it.
To get the parents parent, call find(:xpath, '../..')
.
How to:
Find a link which contains a gitlab icon and check that it links to the correct page:
a href="http://gitlab.com/">
class ="icon gitlab">
a>
link = page.find("a .icon.gitlab").find(:xpath, '..')
link[:href].should == "http://gitlab.com/
Have a look at this tutorial that will give you a good overview for xpath expressions.
Selenium get parent of element in JavaScript:
Selenium get parent of element in Java:
The post Selenium get the parent of an element appeared first on Testingrepository - Talking about selenium , and our passion.
This post first appeared on Testing Repository - Creating Testing, please read the originial post: here