> For the complete documentation index, see [llms.txt](https://tvn.gitbook.io/selenium-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tvn.gitbook.io/selenium-java/locating-elements-with-xpath-axis.md).

# 4.5. Locating elements with XPath axis

| **Axis**                                      | **Description**                                                                                                                    | **Example**                                                  | **Result**                                                                                                           |
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
| **ancestor**                                  | **Selects all ancestors (parent, grandparent, and so on) of the current node.**                                                    | **//td\[text()='John']/ancestor::table**                     | **This will get the table element.**                                                                                 |
| **descendant**                                | **Selects all descendants (children, grandchildren, and so on) of the current node.**                                              | **//table\[@id='table1']/descendant::td\[text()='JoJason']** | **This will get the element from the second column of the third row from the table.**                                |
| <p><strong>following-sibling</strong><br></p> | **Selects all siblings after the current node.**                                                                                   | **//td\[text()='Jason']/following-sibling::td\[1]**          | **his will get the third column from the third row immediately after the column that has Jason as  the text value.** |
| **preceding**                                 | **Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes, and namespace nodes.** | **//td\[text()='John']/preceding::tr**                       | **This will get the header row.**                                                                                    |
| <p><strong>preceding-sibling</strong><br></p> | **Selects all siblings before the current node.**                                                                                  | **.//td\[text()='Smith']/preceding-sibling::td**             | **This will get the first column of third row from the table.**                                                      |

{% embed url="<https://youtu.be/Mw02FwwAJdg>" %}
