CSS Selectors for Test Automation
About this course
A CSS selector is a short expression that points at one or more elements on a page by tag, id, class, attribute, or relationship. In test automation it is usually the first choice for finding elements, because it is fast and reads cleanly. This course teaches CSS selectors for locating elements reliably, with live practice on every selector.
Common CSS selectors
| Selector | Matches |
|---|---|
.btn-primary |
every element with class btn-primary |
#checkout |
the element with id checkout |
input[type='email'] |
email inputs |
nav > a |
links that are direct children of nav |
li:nth-child(2) |
the second list item |
[data-test='submit'] |
the element tagged for testing |
A quick example
/* A stable hook meant for tests, not styling */
[data-test='add-to-cart']
The course covers combinators, pseudo-classes, and how to pick selectors that survive a redesign, 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
- 37 comprehensive lessons
- Learn at your own pace
- Interactive exercises
- Track your progress