Constructor
Parent frame
Selector to locate elements
Locator options
hasText(string | RegExp): Matches elements containing texthasNotText(string | RegExp): Matches elements not containing texthas(Locator): Matches elements containing another locatorhasNot(Locator): Matches elements not containing another locatorvisible(boolean): Matches only visible elements
Filtering Methods
filter
Creates a filtered locator.Filter options
Locator - Filtered locator
first
Returns first matching element.Locator - Locator for first element
last
Returns last matching element.Locator - Locator for last element
nth
Returns nth matching element.Element index (0-based, negative for reverse)
Locator - Locator for nth element
and
Combines with another locator (AND).Locator to combine with
Locator - Combined locator
or
Combines with another locator (OR).Locator to combine with
Locator - Combined locator
Chaining Methods
locator
Creates a descendant locator.Descendant selector or locator
Locator options
Locator - Descendant locator
getByRole
Finds by ARIA role.getByText
Finds by text content.getByLabel
Finds by label text.getByPlaceholder
Finds by placeholder text.getByAltText
Finds by alt text.getByTitle
Finds by title attribute.getByTestId
Finds by test ID.frameLocator
Creates a frame locator.contentFrame
Gets frame content locator.FrameLocator - Frame locator
Action Methods
click
Clicks the element.Click options
button(‘left’ | ‘right’ | ‘middle’): Mouse buttonclickCount(number): Number of clicksdelay(number): Delay between mousedown and mouseupposition(object): Click positionmodifiers(string[]): Modifier keysforce(boolean): Force clicknoWaitAfter(boolean): Don’t wait after clicktimeout(number): Maximum time
Promise<void>
dblclick
Double clicks the element.fill
Fills an input element.Value to fill
Fill options
force(boolean): Force fillnoWaitAfter(boolean): Don’t wait after filltimeout(number): Maximum time
Promise<void>
clear
Clears an input element.Clear options
Promise<void>
type
Types text into element.Text to type
Type options
delay(number): Delay between key pressestimeout(number): Maximum time
Promise<void>
pressSequentially
Presses keys sequentially.press
Presses a key.Key to press (e.g., ‘Enter’, ‘ArrowDown’)
Press options
Promise<void>
check
Checks a checkbox.uncheck
Unchecks a checkbox.setChecked
Sets checkbox state.Whether to check or uncheck
Check options
Promise<void>
selectOption
Selects options.Values to select
Select options
Promise<string[]> - Selected values
hover
Hovers over element.tap
Taps the element.focus
Focuses the element.blur
Blurs the element.dragTo
Drags to another locator.Target locator
Drag options
Promise<void>
setInputFiles
Sets input files.Files to upload
Upload options
Promise<void>
dispatchEvent
Dispatches a DOM event.Event type
Event initialization object
Timeout options
Promise<void>
Content Methods
textContent
Returns text content.Promise<string | null> - Text content or null
innerText
Returns inner text.Promise<string> - Inner text
innerHTML
Returns inner HTML.Promise<string> - Inner HTML
inputValue
Returns input value.Promise<string> - Input value
getAttribute
Returns attribute value.Attribute name
Timeout options
Promise<string | null> - Attribute value or null
allTextContents
Returns all text contents.Promise<string[]> - Array of text contents
allInnerTexts
Returns all inner texts.Promise<string[]> - Array of inner texts
State Methods
isVisible
Checks if visible.Promise<boolean> - True if visible
isHidden
Checks if hidden.Promise<boolean> - True if hidden
isEnabled
Checks if enabled.Promise<boolean> - True if enabled
isDisabled
Checks if disabled.Promise<boolean> - True if disabled
isChecked
Checks if checked.Promise<boolean> - True if checked
isEditable
Checks if editable.Promise<boolean> - True if editable
Evaluation Methods
evaluate
Evaluates JavaScript on element.Function to evaluate
Argument to pass
Timeout options
Promise<R> - Evaluation result
evaluateAll
Evaluates on all matching elements.evaluateHandle
Evaluates and returns JSHandle.Utility Methods
count
Returns number of matching elements.Promise<number> - Count of elements
all
Returns all matching locators.Promise<Locator[]> - Array of locators
boundingBox
Returns bounding box.Promise<Rect | null> - Bounding box or null
screenshot
Takes a screenshot.Screenshot options
path(string): File path to save totype(‘png’ | ‘jpeg’): Image typequality(number): JPEG qualityomitBackground(boolean): Transparent backgroundtimeout(number): Maximum timemask(Locator[]): Elements to mask
Promise<Buffer> - Screenshot buffer
scrollIntoViewIfNeeded
Scrolls element into view.Promise<void>
selectText
Selects text.Promise<void>
waitFor
Waits for element state.Wait options
state(‘attached’ | ‘visible’ | ‘hidden’ | ‘detached’): Element statetimeout(number): Maximum time
Promise<void>
elementHandle
Returns element handle.Promise<ElementHandle> - Element handle
elementHandles
Returns all element handles.Promise<ElementHandle[]> - Array of element handles
page
Returns parent page.Page - Parent page
highlight
Highlights the element.Promise<void>
ariaSnapshot
Returns ARIA snapshot.Promise<string> - ARIA snapshot
describe
Adds custom description.Custom description
Locator - Locator with description
description
Returns custom description.string | null - Custom description or null
Usage Examples
Basic Locator Usage
Filtering Locators
Using Get By Methods
Chaining Locators
Working with Multiple Elements
Related Classes
- Page - Page containing locator
- Frame - Frame containing locator
- ElementHandle - Element handles
- FrameLocator - Frame locators
