class: locator
[26:14] (extern: com.lehman.aussom.ALocator) extends: object
The locator class is the primary element interaction surface in Playwright. It represents a lazy, auto-retrying reference to DOM elements. Instances are obtained by calling page.locator(), page.getByRole(), page.getByText(), and similar factory methods on page or locator objects. Locator methods auto-retry until the element is actionable or a timeout is exceeded.
Methods
-
all ()
Returns a list of locator objects for every element currently matching this locator's selector.
- @r
Alist of locator objects.
- @r
-
count ()
Returns the number of elements currently matching this locator.
- @r
Anint count of matching elements.
- @r
-
first ()
Returns a new locator narrowed to the first matching element.
- @r
Alocator for the first match.
- @r
-
last ()
Returns a new locator narrowed to the last matching element.
- @r
Alocator for the last match.
- @r
-
nth (
int Index)Returns a new locator narrowed to the nth matching element (0-indexed).
- @p
Indexis an int zero-based index of the element to select. - @r
Alocator for the nth match.
- @p
-
filter (
string HasText)Returns a new locator filtered to elements whose visible text contains the given string.
- @p
HasTextis a string of text that must be present in the element. - @r
Afiltered locator.
- @p
-
and (
object Other)Returns a new locator that matches elements satisfying both this locator and the given other locator.
- @p
Otheris a locator to intersect with. - @r
Acombined locator.
- @p
-
or (
object Other)Returns a new locator that matches elements satisfying either this locator or the given other locator.
- @p
Otheris a locator to union with. - @r
Acombined locator.
- @p
-
newLocator (
string Selector)Returns a new locator scoped to descendants matching the given selector within this locator's matched elements.
- @p
Selectoris a string CSS or XPath selector. - @r
Ascoped locator.
- @p
-
getByRole (
string Role)Returns a locator for descendants matching the given ARIA role.
- @p
Roleis a string ARIA role name. - @r
Alocator.
- @p
-
getByText (
string Text)Returns a locator for descendants by visible text.
- @p
Textis a string of visible text to match. - @r
Alocator.
- @p
-
getByLabel (
string Label)Returns a locator for form inputs by associated label text within scope.
- @p
Labelis a string label text to match. - @r
Alocator.
- @p
-
getByPlaceholder (
string Placeholder)Returns a locator for form inputs by placeholder text within scope.
- @p
Placeholderis a string placeholder to match. - @r
Alocator.
- @p
-
getByTestId (
string TestId)Returns a locator for elements by test ID within scope.
- @p
TestIdis a string test ID value. - @r
Alocator.
- @p
-
click ()
Clicks the element. Auto-waits for the element to be actionable.
- @r
Thisobject.
- @r
-
dblclick ()
Double-clicks the element.
- @r
Thisobject.
- @r
-
hover ()
Moves the mouse pointer over the element.
- @r
Thisobject.
- @r
-
tap ()
Taps the element (touch gesture).
- @r
Thisobject.
- @r
-
fill (
string Value)Clears any existing value and fills the element with the provided text. Works for input, textarea, and contenteditable elements.
- @p
Valueis a string value to fill. - @r
Thisobject.
- @p
-
clear ()
Clears the value of an editable element (input, textarea, contenteditable).
- @r
Thisobject.
- @r
-
pressSequentially (
string Text)Types text character-by-character, triggering keydown, keypress, and keyup events for each character.
- @p
Textis a string of text to type sequentially. - @r
Thisobject.
- @p
-
press (
string Key)Presses a single key or key combination on the element.
- @p
Keyis a string key name (e.g. 'Enter', 'Tab', 'Control+a'). - @r
Thisobject.
- @p
-
check ()
Checks the element if it is a checkbox or radio button.
- @r
Thisobject.
- @r
-
uncheck ()
Unchecks the element if it is a checkbox.
- @r
Thisobject.
- @r
-
setChecked (
bool Checked)Sets the checked state of a checkbox or radio button explicitly.
- @p
Checkedis a bool - true to check, false to uncheck. - @r
Thisobject.
- @p
-
selectOption (
string Value)Selects one or more options in a select element by their value strings.
- @p
Valueis a string option value to select. - @r
Alist of strings with the selected option values.
- @p
-
focus ()
Focuses the element.
- @r
Thisobject.
- @r
-
blur ()
Removes focus from the element.
- @r
Thisobject.
- @r
-
dragTo (
object Target)Drags this element to the target locator's element.
- @p
Targetis a locator object representing the drop target. - @r
Thisobject.
- @p
-
dispatchEvent (
string Type)Dispatches a DOM event of the given type on the element.
- @p
Typeis a string DOM event type (e.g. 'click', 'input', 'change'). - @r
Thisobject.
- @p
-
isVisible ()
Returns whether the element is visible.
- @r
Abool - true if visible.
- @r
-
isHidden ()
Returns whether the element is hidden.
- @r
Abool - true if hidden.
- @r
-
isEnabled ()
Returns whether the element is enabled.
- @r
Abool - true if enabled.
- @r
-
isDisabled ()
Returns whether the element is disabled.
- @r
Abool - true if disabled.
- @r
-
isChecked ()
Returns whether the checkbox or radio button element is checked.
- @r
Abool - true if checked.
- @r
-
isEditable ()
Returns whether the element is editable (not readonly and not disabled).
- @r
Abool - true if editable.
- @r
-
boundingBox ()
Returns the bounding box of the element as a map with keys 'x', 'y', 'width', and 'height' in pixels.
- @r
Amap with double values for x, y, width, height, or null if not visible.
- @r
-
getAttribute (
string Name)Returns the value of the named attribute on the element.
- @p
Nameis a string attribute name. - @r
Astring attribute value, or null if the attribute does not exist.
- @p
-
innerHTML ()
Returns the element.innerHTML of the matched element.
- @r
Astring with the inner HTML.
- @r
-
innerText ()
Returns the element.innerText of the matched element (visible text only).
- @r
Astring with the inner text.
- @r
-
textContent ()
Returns the node.textContent of the matched element (includes hidden text).
- @r
Astring with the text content.
- @r
-
inputValue ()
Returns the current value of an input, textarea, or select element.
- @r
Astring with the current input value.
- @r
-
allInnerTexts ()
Returns the innerText of every element matching this locator.
- @r
Alist of strings.
- @r
-
allTextContents ()
Returns the textContent of every element matching this locator.
- @r
Alist of strings.
- @r
-
evaluate (
string Expression)Evaluates a JavaScript expression with the matched element as the first argument and returns the serialized result.
- @p
Expressionis a string JavaScript expression (e.g. 'el => el.value'). - @r
Theresult of the expression.
- @p
-
evaluateAll (
string Expression)Evaluates a JavaScript expression against all matching elements and returns the serialized result.
- @p
Expressionis a string JavaScript expression (e.g. 'els => els.length'). - @r
Theresult of the expression.
- @p
-
waitFor (
string State = "visible")Waits for the element to become visible (default state) or to satisfy another state such as 'hidden', 'attached', or 'detached'.
- @p
Stateis a string state to wait for: 'visible', 'hidden', 'attached', 'detached'. - @r
Thisobject.
- @p
-
screenshot (
string Path)Captures a screenshot of the matched element and saves it to disk.
- @p
Pathis a string file path where the screenshot will be saved. - @r
Thisobject.
- @p
-
highlight ()
Highlights the matched element on screen for visual debugging.
- @r
Thisobject.
- @r
-
page ()
Returns the page that this locator belongs to.
- @r
Apage object.
- @r