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.

Locator text

Locator text

In this lesson, we'll learn about the get by text locator, which helps you locate elements based on their text. Let's say we'd like to select this with muted text. So let's go ahead and inspect it. You can see it's a small element inside H3 with the text as with muted text. So what we can do is do page get by text and just provide it the text. In this case it is with muted text. And we can just go ahead and say highlight it. You can see that gets highlighted. Now of course you would not like to select just a certain piece of text. Instead you can apply the same technique on other elements like links and buttons as well. So what you can do is just say like get by text and let's say we like to have this small button. So I can just say like small button and then I can just say highlight it. You can see small button gets highlighted. Similarly we can select other elements as well. Let's say we'd like to select a button that is this middle right here. So if I click it, you can see for a…

Contents