Locator

Playwright\Locator\LocatorInterface

Methods

click()

void
function click(array|ClickOptions $options = []): void

fill()

void
function fill(string $value, array|FillOptions $options = []): void

type()

void
function type(string $value, array|TypeOptions $options = []): void

pressSequentially()

void

Press keys sequentially to type the provided text.

function pressSequentially(string $text, array|TypeOptions $options = []): void

press()

void
function press(string $key, array|PressOptions $options = []): void

check()

void
function check(array|CheckOptions $options = []): void

uncheck()

void
function uncheck(array|UncheckOptions $options = []): void

hover()

void
function hover(array|HoverOptions $options = []): void

dragTo()

void

Drag this element to target element.

function dragTo(LocatorInterface $target, array|DragToOptions $options = []): void

drop()

void

Drop files or clipboard-like data onto this element, as an external application would. The target must accept the drop by calling preventDefault() in its dragover handler, otherwise the drop is rejected and this method throws.

function drop(array|DropPayload $payload, array|DropOptions $options = []): void

dblclick()

void
function dblclick(array|DblClickOptions $options = []): void

clear()

void
function clear(array|ClearOptions $options = []): void

focus()

void
function focus(): void

blur()

void
function blur(): void

ariaSnapshot()

string
function ariaSnapshot(array|AriaSnapshotOptions $options = []): string

boundingBox()

?array
function boundingBox(array|BoundingBoxOptions $options = []): ?array

dispatchEvent()

void
function dispatchEvent(string $type, mixed $eventInit = [], array|DispatchEventOptions $options = []): void

scrollIntoViewIfNeeded()

void
function scrollIntoViewIfNeeded(array|ScrollIntoViewIfNeededOptions $options = []): void

screenshot()

?string
function screenshot(?string $path = null, array|LocatorScreenshotOptions $options = []): ?string

allInnerTexts()

array
function allInnerTexts(): array

allTextContents()

array
function allTextContents(): array

innerHTML()

string
function innerHTML(): string

innerText()

string
function innerText(): string

inputValue()

string
function inputValue(): string

isAttached()

bool
function isAttached(): bool

isChecked()

bool
function isChecked(): bool

isDisabled()

bool
function isDisabled(): bool

isEditable()

bool
function isEditable(): bool

isEmpty()

bool
function isEmpty(): bool

isEnabled()

bool
function isEnabled(): bool

isHidden()

bool
function isHidden(): bool

isVisible()

bool
function isVisible(): bool

locator()

self
function locator(string $selector): self

getByAltText()

self
function getByAltText(string $text, array|GetByOptions $options = []): self

getByLabel()

self
function getByLabel(string $text, array|GetByOptions $options = []): self

getByPlaceholder()

self
function getByPlaceholder(string $text, array|GetByOptions $options = []): self

getByRole()

self
function getByRole(string $role, array|GetByRoleOptions $options = []): self

getByTestId()

self
function getByTestId(string $testId): self

getByText()

self
function getByText(string $text, array|GetByOptions $options = []): self

getByTitle()

self
function getByTitle(string $text, array|GetByOptions $options = []): self

waitFor()

void
function waitFor(array|WaitForOptions $options = []): void

selectOption()

array
function selectOption(string|array $values, array|SelectOptionOptions $options = []): array

setInputFiles()

void
function setInputFiles(string|array $files, array|SetInputFilesOptions $options = []): void

textContent()

?string
function textContent(array|TextContentOptions $options = []): ?string

getAttribute()

?string
function getAttribute(string $name, array|GetAttributeOptions $options = []): ?string

count()

int
function count(): int

all()

array
function all(): array

first()

self
function first(): self

last()

self
function last(): self

nth()

self
function nth(int $index): self

evaluate()

mixed
function evaluate(string $expression, mixed $arg = null): mixed

evaluateHandle()

JSHandleInterface

Returns a handle to the result instead of a serialized copy, so a DOM node or a live object survives the round trip. Strict: the selector has to resolve to exactly one element. Dispose the handle once done with it, otherwise it pins its target until the page closes.

function evaluateHandle(string $expression, mixed $arg = null): JSHandleInterface

waitForFunction()

self

Re-runs the expression, with the matched element as its first argument, until it returns a truthy value.

function waitForFunction(string $pageFunction, mixed $arg = null, array|WaitForFunctionOptions $options = []): self

page()

PageInterface

The page this locator resolves against.

function page(): PageInterface

evaluateAll()

mixed

Runs the expression once over every matching element, passing them as an array. Unlike evaluate(), which targets the first match, and it does not wait for elements to appear: an empty match evaluates against an empty array.

function evaluateAll(string $expression, mixed $arg = null): mixed

highlight()

void

Paints a highlight over the matching elements until the next action. A debugging aid, visible in headed mode only; it changes nothing in the page.

function highlight(): void

hideHighlight()

void

Removes the highlight painted by highlight().

function hideHighlight(): void

selectText()

void
function selectText(array|SelectTextOptions $options = []): void

setChecked()

void
function setChecked(bool $checked, array|SetCheckedOptions $options = []): void

tap()

void
function tap(array|TapOptions $options = []): void

frameLocator()

FrameLocatorInterface
function frameLocator(string $selector): FrameLocatorInterface

getSelector()

string
function getSelector(): string

filter()

self
function filter(array|FilterOptions $options = []): self

and()

self
function and(LocatorInterface $locator): self

or()

self
function or(LocatorInterface $locator): self

describe()

self
function describe(string $description): self

normalize()

self

Resolves the current match into a locator built from test ids and aria roles. Turns an implementation-detail selector into a user-facing one, so it needs a live match and hits the browser.

function normalize(): self

contentFrame()

FrameLocatorInterface
function contentFrame(): FrameLocatorInterface