---
title: "More Working with XPATH"
slug: "more-working-with-xpath"
updated: 2023-01-06T15:49:20Z
published: 2023-01-06T15:49:19Z
canonical: "docs.catchpoint.com/more-working-with-xpath"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.catchpoint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# More Working with XPATH

XPath is used to navigate through elements and attributes in a tree-structured document (XML or HTML). Selenium commands use XPath as an element locator. XPath can be tested for matching results using developer tools in a browser.

Test any XPath for its match using Developer Tool (using Firefox/Firebug)
![](https://cdn.document360.io/cb4af8f9-6751-4fd2-b39c-07aae832badb/Images/Documentation/201987179-xpath1.png)

1. Load a page in a browser and open the developer tool.
2. Place valid XPath in the "evaluate function" field within the console tab.
Example: `document.evaluate("XPath here", document, null, 7, null);`
3. Hit **Run** to get results.
4. Hover mouse over a result to see the corresponding element highlighted on the page.

 Sample HTML document used for reference in path expression construction.

![](https://cdn.document360.io/cb4af8f9-6751-4fd2-b39c-07aae832badb/Images/Documentation/201987199-xpath2.png)

**Selecting Elements**
XPath uses path expressions to select elements (aka "nodes", not to be confused with Catchpoint's test nodes) in an XML/HTML document. The node is selected by following a path or steps. Some useful path expressions are listed below:

<table>
<tbody>
<tr>
	<th colspan="2"><strong>Expression</strong></th>
	<th colspan="2"><strong> Description</strong></th>
</tr>
<tr>
	<td colspan="2"><strong>/</strong></td>
	<td colspan="2"><strong> Selects matching elements contained in the specified node, starting from the root node.</strong></td>
</tr>
<tr>
	<td></td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">/HTML</td>
	<td>Selects the root element HTML.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">/HTML/body</td>
	<td>Selects the body element that is child of HTML.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">/HTML/body/div/form/input[1]</td>
	<td>Selects the first input element inside the form.</td>
</tr>
<tr>
	<td colspan="2"><strong>//</strong></td>
	<td colspan="2"><strong>Selects all matching nodes in the document no matter where they are in the tree.</strong></td>
</tr>
<tr>
	<td>           </td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//button</td>
	<td>Selects all button elements anywhere in the document.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//form</td>
	<td>Selects all form elements no matter where they are in the document.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//input[@name='submit']</td>
	<td>Selects all input elements with name 'submit' no matter where they are in the document.</td>
</tr>
<tr>
	<td colspan="2"><strong>@</strong></td>
	<td colspan="2"><strong> Matches Attributes.</strong></td>
</tr>
<tr>
	<td>           </td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//div[@class='one']/form</td>
	<td>Selects form element inside a div with class='one'.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//form[@name='account']</td>
	<td>Selects form with name='account'.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//input[@id='fname']</td>
	<td>Selects input with id='fname'.</td>
</tr>
<tr>
	<td colspan="2"><strong>..</strong></td>
	<td colspan="2"><strong> Selects the parent of the current node.</strong></td>
</tr>
<tr>
	<td>           </td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">/html/body/..</td>
	<td>Selects the HTML element which is the parent of the body.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//body/..</td>
	<td>Selects the HTML element which is the parent of the body.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//input[@id='fname']/..</td>
	<td>Selects form element which is the parent of input with id=`fname`.  </td>
</tr>
<tr>
	<td colspan="2"><strong>*</strong></td>
	<td colspan="2"><strong>Wildcard - matches any node</strong></td>
</tr>
<tr>
	<td><em>                            </em></td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//*</td>
	<td>Selects all elements in the document.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//form[@name='account']/*</td>
	<td>Selects all the child nodes of the form element with name='account'.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//*[@name='account']</td>
	<td>Selects the form element with name='account'.</td>
</tr>
<tr>
	<td colspan="2"><strong> @*</strong></td>
	<td colspan="2"><strong> Matches any node with at least one attribute.</strong></td>
</tr>
<tr>
	<td><em>           </em></td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//select[@*]</td>
	<td>Matches all select elements which have at least one attribute.</td>
</tr>
<tr>
	<td colspan="2"><strong> node()</strong></td>
	<td colspan="2"><strong> Matches any node of any kind</strong></td>
</tr>
<tr>
	<td><em>                            </em></td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">/HTML/node()</td>
	<td>Selects the child nodes of HTML, in this case &lt;head&gt; and &lt;body&gt;.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//form/node()[last()]</td>
	<td>Selects the last child element under form, in this case input with name=`submit`.  </td>
</tr>
<tr>
    <td colspan="2"><strong>[ ... ]</strong></td>
	<td colspan="2"><strong>Predicate - used to find a specific node or a node that contains a specific value. Predicates are always embedded in square brackets.</strong></td>
</tr>
<tr>
	<td><em>                            </em></td>
	<td colspan="2"><strong><em>Path Expression</em></strong></td>
	<td><strong><em>Result</em></strong></td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//form/input[1]</td>
	<td>Selects the first child input element under form.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//form/input[position()=2]</td>
	<td>Selects second input element under form.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//a[text()='Sign In']</td>
	<td>Selects anchor tag whose inner text is exactly `Sign In`.</td>
</tr>
<tr>
	<td> </td>
	<td colspan="2">//a[contains(.,'Sign')]</td>
	<td>Selects anchor tag whose inner text contains `Sign`.   </td>
</tr>
</tbody> </table>
