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.

UI testing class attribute

UI testing class attribute

For this test case, we have to select a primary button that is blue in color and with the class of button primary, which is saved or mentioned in the info section. Now if I go ahead and inspect the same, you will see we have three buttons with the same tag name, that is the role and the same text on the same. going to use our rule locator. Instead, we have to use the class names of our buttons, you will see that this button right here, which is our primary button, which we have to locate has class one inside of it. Now you may think we can go ahead and just use the same. Well, notice the position of the buttons. If I go ahead and reload the page, notice that now it has changed. So the position of the buttons is generated dynamically. And so does this class one, two, and three. So we cannot rely on the same to select our primary button. Instead, we can use the button hyphen primary class to identify our button. So let's go ahead and use CSS selectors to select this element based on the…

Contents