Sunday, 28 May 2023

Playwright: different ways to get locators

Locators are used to find the elements in a page.

 

Below table summarize  are the recommended locators.

 

Locator

Description

page.getByRole()

Locate by explicit and implicit accessibility attributes.

page.getByText()

locate by text content.

page.getByLabel()

locate a form control by associated label's text.

page.getByPlaceholder()

locate an input by placeholder.

page.getByAltText()

locate an element, usually image, by its text alternative.

page.getByTitle()

locate an element by its title attribute.

page.getByTestId()

locate an element based on its data-testid attribute.

page.locator()

Locate the element by given selector.

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment