From the course: Playwright Python and Pytest for Web Automation Testing: Master Modern Web Testing with Playwright and Pytest in Python

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

CSS selectors pseudo classes

CSS selectors pseudo classes

In the previous lesson, we learned about how can we use CSS selectors to locate web elements. In this lesson, we'll learn about the pseudo classes which playwright offers to use and select web elements based on different conditions. So let's say we want to do is select all the heading elements in the page. So we will likely use the page locator, specify the tag name which will be h1 and then just highlight all of the instances. You can see these are all the headings with the h1 tag name. Now let's say what we want to do is only select this heading element with the nav bars text. Now here what we can do is just use the get by text locator. But if you really want to use the CSS one instead, then we can just use the text pseudo class which playwright offers. Now pseudo class is just like a function which we can run on any CSS selector like this one. So let's go ahead and do that. So we'll start with our CSS selector that is H1 and now because we want to use a pseudo class, what we do is…

Contents