xpath @class code example
Example 1: xpath in selenium
How many types of xpath are there?
- Two types of xpath
-> What are the two types?
- Absolute and Relative xpath
- starts with /
- Starts from the very beginning of the html page,
and goes down to desired web element 1 by 1.
- it is NOT dependable at all.
- easly brakes if there is any minimal changes
in the structure of the HTML page.
- starts with //
- // means you can start from anywhere in the HTML code
- it will jump to the first matching value and return it
- There are MANY different options to use relative xpath
Commmon xpaths:
-> instead of giving tag name if you pass * it return all the web elements
that contain given attribute and value regardless of the tag name.
Example 2: how to mention a div with class in xpath
button[@type='submit']
button[@class='btn btn-success']
button[@type='submit'][@class='btn btn-success']
Example 3: how to mention a div with class in xpath
button[type='submit']
button[class='btn btn-success']
button[type='submit'][class='btn btn-success']