Constructor
Frame
required
Parent frame
string
required
Selector to locate elements
LocatorOptions
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.LocatorOptions
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.number
required
Element index (0-based, negative for reverse)
Locator - Locator for nth element
and
Combines with another locator (AND).Locator
required
Locator to combine with
Locator - Combined locator
or
Combines with another locator (OR).Locator
required
Locator to combine with
Locator - Combined locator
Chaining Methods
locator
Creates a descendant locator.string | Locator
required
Descendant selector or locator
LocatorOptions
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.ClickOptions
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.string
required
Value to fill
FillOptions
Fill options
force(boolean): Force fillnoWaitAfter(boolean): Don’t wait after filltimeout(number): Maximum time
Promise<void>
clear
Clears an input element.FillOptions
Clear options
Promise<void>
type
Types text into element.string
required
Text to type
TypeOptions
Type options
delay(number): Delay between key pressestimeout(number): Maximum time
Promise<void>
pressSequentially
Presses keys sequentially.press
Presses a key.string
required
Key to press (e.g., ‘Enter’, ‘ArrowDown’)
PressOptions
Press options
Promise<void>
check
Checks a checkbox.uncheck
Unchecks a checkbox.setChecked
Sets checkbox state.boolean
required
Whether to check or uncheck
CheckOptions
Check options
Promise<void>
selectOption
Selects options.string | string[] | SelectOption | SelectOption[]
required
Values to select
SelectOptionOptions
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.Locator
required
Target locator
DragAndDropOptions
Drag options
Promise<void>
setInputFiles
Sets input files.string | string[] | FilePayload | FilePayload[]
required
Files to upload
SetInputFilesOptions
Upload options
Promise<void>
dispatchEvent
Dispatches a DOM event.string
required
Event type
any
Event initialization object
TimeoutOptions
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.string
required
Attribute name
TimeoutOptions
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
required
Function to evaluate
any
Argument to pass
TimeoutOptions
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.ScreenshotOptions
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.WaitForOptions
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.string
required
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
