Xpath Function Using Ancestors
Xpaths Ancestors:-
In this method the context node, parent or its grandparents are selected via the Ancestors axes. In the example below, the first one will point to the parent node of the login fields where the other will point to its grandparent node which is the tag form in this case.
Example 1: Xpath= //input[@name='email']//ancestor::div[1]
Example 2: Xpath= //input[@name='email']//ancestor::form