# 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>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tvn.gitbook.io/selenium-java/locating-elements-with-xpath-axis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
