Get grandParent using xpath in selenium webdriver

python, selenium, selenium-webdriver, xpath

Solution

Instead of targeting a deeper level element and going up in the tree, you can select the higher level element and test for a descendant node attribute:

.//div[@class="myclass"][.//input[@name="myname"]]

Problem

``` <div class="myclass"> <span>...</span> <div> <table> <colgroup>...</> <tbody> <tr>...</tr> <tr> <td> <input ...name="myname" ...> </td> </tr> <tr>...</tr> <tbody> </table> </div> </div> ``` this is my html code ... I have attribute "name" ..so I can access tag ...but from this line I want to access top element. One way is that I write `driver.find_element_by_xpath('..')` 6-7 times to get that parent but I dont know how many steps I have to go above. I simply want a xpath expression or similar thing to access top . I'm using Selenium webdriver with python

Original source