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.

Locating with CSS selectors

Locating with CSS selectors

In the previous lessons, we discussed about many locators, that is the get by role, get by label, get by text, and so on. In this lesson, we'll learn about the CSS selectors and how can we use them to locate web elements using playwright. Now, one thing I should mention before using CSS selectors is that playwright documentations recommend to use the locators over any other thing but you can always use other things like css selectors to select web elements because it provides more freedom when selecting web elements css selectors can be used to select web elements based on their tag name class name id or any attribute and its value so let's go ahead and see how can we do the same now to test css selectors we can use the dev tools and while being in dev tools hit ctrl and f and you will see a search bar like thing popping up in which we can test our selectors so let's say what we want to do is select all the heading elements in the page so let's just go ahead and highlight the element…

Contents