XPath Operators

This lesson comprehensively discusses the operators that are provided by XPath.

What is an XPath operator?

XPath operators are defined on nodes/elements, returning either a node-set, a string, a boolean, or a number, as shown in the example below.

HTML structure considered for demonstration

Let us consider the following HTML structure to learn about the different operators present in XPath:

<table>
    <tr>
        <td><span id="1">1</span></td>
        <td><span id="2">2</span></td>
        <td><span id="3">3</span></td>
    </tr>
    <tr>
        <td><span id="4">4</span></td>
        <td><span id="5">5</span></td>
        <td><span id="6">6</span></td>
    </tr>
    <tr>
        <td><span id="7">7</span></td>
        <td><span id="8">8</span></td>
        <td><span id="10">10</span></td>
    </tr>
</table>

List of operators

The table below shows the list of operators that can be used in XPath:

Get hands-on with 1200+ tech skills courses.