XPath lets you specify an HTML element or a set of HTML elements. This article provides the basic elements you need to get started, but keep in mind that there are many ways to write an XPath. Take the time to practice and find a method that works for you.
How to check XPath in HTML
- Right-click an item on the web page.
- Select Inspect.
- Press Ctrl+F to search for the XPath match.
XPath Syntax has three elements
- Axis: Specifies the tree relationship and the direction to navigate from node to node.
- Node test: The name of the HTML element you want to select.
- Zero or more predicates: Filters a node to refine results. These can be functions, numbers, or operators within square brackets.
When you want to write a custom XPath for a capture action, hover over the element you want to select, then right-click and select Inspect to open the HTML document that corresponds to the element.
Take your time to become familiar with the website and the HTML. Look for similarities between the HTML and the text on the website.
Let's simplify the HTML element as if you were searching for a family tree for a specific person. To write your first XPath, specify the axis and name, then add a filter in brackets.
We want to search all HTML elements , so we'll set our axis to descendant-or-self using the short-hand "// ." The name of the element is "travis." To filter out any other potential matches, we'll add a filter using the attribute of hair that is equal to brown.
Write an XPath to select the div below.