LocatorScope Class
Creates the locators of the elements of a page, of a component or of the elements of another locator, as Playwright does. A locator finds its elements again each time it is used, so it keeps working when the page renders new elements. The texts are matched as substrings, ignoring the case and collapsing the white space, unless they are exact. The elements of the open shadow roots are found too.
public abstract class LocatorScopeMethods
| Name | Description |
|---|---|
| GetByAltText(string, bool) | Creates a locator of the elements (usually images) whose alt attribute contains a text. |
| GetByAltText(Regex) | Creates a locator of the elements whose alt attribute matches a regular expression. |
| GetByLabel(string, bool) | Creates a locator of the elements labelled by a text: the elements referenced by aria-labelledby, else the aria-label attribute, else the label elements of a form control. |
| GetByLabel(Regex) | Creates a locator of the elements whose label matches a regular expression. |
| GetByPlaceholder(string, bool) | Creates a locator of the elements whose placeholder attribute contains a text. |
| GetByPlaceholder(Regex) | Creates a locator of the elements whose placeholder attribute matches a regular expression. |
| GetByRole(string, string?, GetByRoleOptions?) | Creates a locator of the elements that have an ARIA role and, optionally, an accessible name (GetByRole("button", "Save")). The elements hidden from the accessibility tree are not found, unless GetByRoleOptions.IncludeHidden is true. |
| GetByRole(string, Regex, GetByRoleOptions?) | Creates a locator of the elements that have an ARIA role and an accessible name that matches a regular expression. |
| GetByTestId(string) | Creates a locator of the elements whose test identifier is a value: the data-testid attribute by default (see TestPageSettings.TestIdAttribute). The value is compared as is. |
| GetByTestId(Regex) | Creates a locator of the elements whose test identifier matches a regular expression. |
| GetByText(string, bool) | Creates a locator of the smallest elements that contain a text: an element is found when its text matches, and the text of none of its children matches. The text of an input button is its value. |
| GetByText(Regex) | Creates a locator of the smallest elements whose text matches a regular expression. |
| GetByTitle(string, bool) | Creates a locator of the elements whose title attribute contains a text. |
| GetByTitle(Regex) | Creates a locator of the elements whose title attribute matches a regular expression. |
| Locator(string) | Creates a locator of the elements that match a CSS selector. |
GetByAltText overloads
GetByAltText(string, bool)
LocatorScope.csCreates a locator of the elements (usually images) whose alt attribute contains a text.
GetByAltText(Regex)
LocatorScope.csGetByLabel overloads
GetByLabel(string, bool)
LocatorScope.csCreates a locator of the elements labelled by a text: the elements referenced by aria-labelledby, else the aria-label attribute, else the label elements of a form control.
GetByLabel(Regex)
LocatorScope.csGetByPlaceholder overloads
GetByPlaceholder(string, bool)
LocatorScope.csCreates a locator of the elements whose placeholder attribute contains a text.
GetByPlaceholder(Regex)
LocatorScope.csGetByRole overloads
GetByRole(string, string?, GetByRoleOptions?)
LocatorScope.csCreates a locator of the elements that have an ARIA role and, optionally, an accessible name (GetByRole("button", "Save")). The elements hidden from the accessibility tree are not found, unless GetByRoleOptions.IncludeHidden is true.
public Locator GetByRole(string role, string? name = null, GetByRoleOptions? options = null)Parameters
rolestring- The computed ARIA role (
button,link,textbox,heading...). namestring?- A substring of the accessible name, ignoring the case (see
GetByRoleOptions.Exact), or null to match any name. optionsGetByRoleOptions?- The states of the elements, or null to match any state.
Returns
Locator The locator.
GetByRole(string, Regex, GetByRoleOptions?)
LocatorScope.csCreates a locator of the elements that have an ARIA role and an accessible name that matches a regular expression.
public Locator GetByRole(string role, Regex name, GetByRoleOptions? options = null)Parameters
rolestring- The computed ARIA role.
nameRegex- The regular expression.
optionsGetByRoleOptions?- The states of the elements, or null to match any state.
Returns
Locator The locator.
GetByTestId overloads
GetByTestId(string)
LocatorScope.csCreates a locator of the elements whose test identifier is a value: the data-testid attribute by default (see TestPageSettings.TestIdAttribute). The value is compared as is.
GetByTestId(Regex)
LocatorScope.csGetByText overloads
GetByText(string, bool)
LocatorScope.csCreates a locator of the smallest elements that contain a text: an element is found when its text matches, and the text of none of its children matches. The text of an input button is its value.
GetByText(Regex)
LocatorScope.csGetByTitle overloads
GetByTitle(string, bool)
LocatorScope.csCreates a locator of the elements whose title attribute contains a text.