Skip to main content
Locator other methods for the Playwright driver.

selectText

Selects all text content of the element.
This method waits for actionability checks, then focuses the element and selects all text content.
Upstream docs
options
{ force?: boolean; timeout?: number }
await locator.selectText();

highlight

Highlights the element on screen (for debugging).
Useful for debugging during test development. Not recommended for production tests.
Upstream docs
await locator.highlight();

boundingBox

Returns the bounding box of the element, or null if not visible.
Returns { x, y, width, height } in pixels relative to the main frame viewport. Scrolling affects the coordinates. Returns null if element is not visible.
Upstream docs
options
PlaywrightBoundingBoxOptions
result
PlaywrightBoundingBox | null
Return value
await locator.boundingBox();

elementHandle

Resolves to the ElementHandle of the element.
Returns the handle to the element that matches this locator. Throws if no elements or multiple elements match.
Upstream docs
options
{ timeout?: number }
result
RemotePlaywrightElementHandle
Return value
await locator.elementHandle();

elementHandles

Resolves to all ElementHandles matching this locator.
Returns an empty array if no elements match.
Upstream docs
result
RemotePlaywrightElementHandle[]
Return value
await locator.elementHandles();

and

Creates a locator that matches both this locator AND the argument.
Both conditions must be satisfied for an element to match.
Upstream docs
locator
RemotePlaywrightLocator
required
Additional locator to match
result
RemotePlaywrightLocator
Return value
await locator.and(/* RemotePlaywrightLocator */);

or

Creates a locator that matches this locator OR the argument.
Either condition being satisfied will match. Be careful with strict mode - if both match, use .first() to select one.
Upstream docs
locator
RemotePlaywrightLocator
required
Alternative locator to match
result
RemotePlaywrightLocator
Return value
await locator.or(/* RemotePlaywrightLocator */);

contentFrame

Returns a FrameLocator pointing to the iframe this locator points to.
Useful when you have a Locator to an iframe and want to interact with its content.
Upstream docs
result
RemotePlaywrightFrameLocator
Return value
await locator.contentFrame();

page

Returns the Page that this locator belongs to. Upstream docs
result
RemotePlaywrightPage
Return value
await locator.page();