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 alt text

Locator alt text

In this lesson, we'll learn how can we use the get by alt text locator to locate images. So first of all, we'll like some images to locate. So let's go to unsplash.com. You will find the link of the same in the resources. You can see it is a free images site with a lot of images, which we can select. So let's say we'd like to select this image right here. And if you're not familiar with it, HTML images always come with a alt property that is like a textual description of the image. That is, you can see this image right here has some people with some fruits. And if I read the alt text, you can see it says a group of people sitting around a table with food. So what we can do is just copy it. And now we would like to select this image based on its alt text. So we can use page get by alt text and provide it the alternative text, which is this right here. And now I can just go ahead and select it. And then let's highlight it as well. Hit enter. You can see the image gets highlighted…

Contents