XPath: Locate Elements Using XPath
About this course
XPath is a query language for selecting nodes in an HTML or XML document. In test automation you use it to find an element by its tag, its visible text, or an attribute, and to walk up or across the tree when there is no clean id or class to grab. This course covers XPath for locating elements, with live practice on every query you write.
Common XPath expressions
| Expression | Selects |
|---|---|
//button |
every button on the page |
//input[@name='email'] |
the input whose name is email |
//*[text()='Log in'] |
any element whose text is "Log in" |
//label[.='Email']/following::input[1] |
the first input after the Email label |
(//tr)[2] |
the second table row |
A quick example
# A button found by its visible text, not a brittle id
//button[normalize-space()='Add to cart']
The course goes further into axes, predicates, and when a CSS selector is the better choice, all with instant feedback.
Course Content
About your instructor
Roy de Kleijn · Software testing trainer
Roy de Kleijn has more than 15 years of hands-on experience in software testing and test automation. He writes and maintains every Testsmith course, so what you practise matches how the work is really done.
Connect on LinkedInDon't have an account? Register
What you get
- 28 comprehensive lessons
- Learn at your own pace
- Interactive exercises
- Track your progress