Page
Playwright\Page\PageInterface
Methods
pause()
selfOpens Playwright Inspector and pauses script execution.
function pause(): self
evaluateHandle()
JSHandleInterfaceReturns a handle to the result instead of a serialized copy, so a DOM node or a live object survives the round trip. Dispose the handle once done with it, otherwise it pins its target until the page closes.
function evaluateHandle(string $expression, mixed $arg = null): JSHandleInterface
locator()
LocatorInterfacefunction locator(string $selector, array|LocatorOptions $options = []): LocatorInterface
getByAltText()
LocatorInterfacefunction getByAltText(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface
getByLabel()
LocatorInterfacefunction getByLabel(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface
getByPlaceholder()
LocatorInterfacefunction getByPlaceholder(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface
getByRole()
LocatorInterfacefunction getByRole(string $role, array|GetByRoleOptions $options = []): LocatorInterface
getByTestId()
LocatorInterfacefunction getByTestId(string $testId, array|LocatorOptions $options = []): LocatorInterface
getByText()
LocatorInterfacefunction getByText(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface
getByTitle()
LocatorInterfacefunction getByTitle(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface
goto()
?ResponseInterfacefunction goto(string $url, array|GotoOptions $options = []): ?ResponseInterface
click()
selffunction click(string $selector, array|ClickOptions $options = []): self
dragAndDrop()
selffunction dragAndDrop(string $source, string $target, array|DragAndDropOptions $options = []): self
altClick()
selffunction altClick(string $selector, array|ClickOptions $options = []): self
controlClick()
selffunction controlClick(string $selector, array|ClickOptions $options = []): self
shiftClick()
selffunction shiftClick(string $selector, array|ClickOptions $options = []): self
type()
selffunction type(string $selector, string $text, array|TypeOptions $options = []): self
screenshot()
stringfunction screenshot(?string $path = null, array|ScreenshotOptions $options = []): string
pdf()
stringfunction pdf(?string $path = null, array|PdfOptions $options = []): string
pdfContent()
stringfunction pdfContent(array|PdfOptions $options = []): string
content()
?stringfunction content(): ?string
consoleMessages()
arrayConsole messages already recorded for this page, oldest first. Unlike the console event, this reads history, so messages logged before any listener existed are still returned. The default filter keeps only what was logged since the last navigation.
function consoleMessages(array $options = []): array
clearConsoleMessages()
selfDiscards the recorded console history without touching event listeners.
function clearConsoleMessages(): self
clearPageErrors()
selfDiscards the uncaught page errors recorded so far.
function clearPageErrors(): self
ariaSnapshot()
stringCaptures the accessibility tree of the whole page as YAML.
function ariaSnapshot(array|AriaSnapshotOptions $options = []): string
addInitScript()
selfQueues a script to run before any of the page's own scripts. It runs again on every navigation and in every frame the page creates, so it is the place to stub an API or seed state a page reads at startup.
function addInitScript(string $script): self
evaluate()
mixedfunction evaluate(string $expression, mixed $arg = null): mixed
emulateMedia()
selfOverrides the CSS media type and media features the page reports. An omitted feature keeps whatever override is in place; pass 'no-override' to give it back to the browser default.
function emulateMedia(array|EmulateMediaOptions $options = []): self
requestGC()
selfAsks the browser to collect garbage, so a WeakRef held by the page can be observed as cleared. Collection is best effort, never guaranteed.
function requestGC(): self
waitForSelector()
LocatorInterfacefunction waitForSelector(string $selector, array|WaitForSelectorOptions $options = []): LocatorInterface
close()
voidfunction close(): void
isClosed()
boolfunction isClosed(): bool
bringToFront()
selffunction bringToFront(): self
context()
BrowserContextInterfacefunction context(): BrowserContextInterface
clock()
ClockInterfaceFake timers for this page. The clock belongs to the browser context, so installing it here affects every page of that context.
function clock(): ClockInterface
video()
?VideoInterfaceVideo recorded for this page, or null when the context does not record one. The file is only complete once the page is closed, so save or delete it after closing the page.
function video(): ?VideoInterface
hideHighlight()
selfRemoves every highlight painted on this page by LocatorInterface::highlight().
function hideHighlight(): self
cookies()
arrayfunction cookies(?array $urls = null): array
goBack()
selffunction goBack(array|NavigationHistoryOptions $options = []): self
goForward()
selffunction goForward(array|NavigationHistoryOptions $options = []): self
reload()
selffunction reload(array|NavigationHistoryOptions $options = []): self
setContent()
selffunction setContent(string $html, array|SetContentOptions $options = []): self
url()
stringfunction url(): string
title()
stringfunction title(): string
viewportSize()
?arrayfunction viewportSize(): ?array
setViewportSize()
selffunction setViewportSize(int $width, int $height): self
setDefaultNavigationTimeout()
selffunction setDefaultNavigationTimeout(int $timeout): self
setDefaultTimeout()
selffunction setDefaultTimeout(int $timeout): self
setExtraHTTPHeaders()
selffunction setExtraHTTPHeaders(array $headers): self
waitForLoadState()
selffunction waitForLoadState(string $state = 'load', array|WaitForLoadStateOptions $options = []): self
waitForFunction()
selffunction waitForFunction(string $pageFunction, mixed $arg = null, array|WaitForFunctionOptions $options = []): self
waitForURL()
selffunction waitForURL($url, array|WaitForUrlOptions $options = []): self
addScriptTag()
selffunction addScriptTag(array|ScriptTagOptions $options): self
addStyleTag()
selffunction addStyleTag(array|StyleTagOptions $options): self
frameLocator()
FrameLocatorInterfacefunction frameLocator(string $selector): FrameLocatorInterface
keyboard()
KeyboardInterfacefunction keyboard(): KeyboardInterface
mouse()
MouseInterfacefunction mouse(): MouseInterface
touchscreen()
TouchscreenInterfaceTouch input for this page. The owning context must have been created with hasTouch enabled, otherwise the browser ignores the events.
function touchscreen(): TouchscreenInterface
localStorage()
WebStorageInterfaceThe localStorage of the page's current origin.
function localStorage(): WebStorageInterface
sessionStorage()
WebStorageInterfaceThe sessionStorage of the page's current origin.
function sessionStorage(): WebStorageInterface
screencast()
ScreencastInterfaceThe page's screencast, to record a video and annotate it.
function screencast(): ScreencastInterface
events()
PageEventHandlerInterfacefunction events(): PageEventHandlerInterface
route()
voidfunction route(string $url, callable $handler): void
unroute()
voidfunction unroute(string $url, ?callable $handler = null): void
unrouteAll()
voidRemoves every route registered on this page in one call. 'behavior' decides what happens to handlers still running: wait for them, wait but swallow their errors, or return without waiting.
function unrouteAll(array $options = []): void
handleDialog()
voidfunction handleDialog(string $dialogId, bool $accept, ?string $promptText = null): void
getPageIdForTransport()
stringfunction getPageIdForTransport(): string
waitForEvents()
voidfunction waitForEvents(): void
waitForPopup()
selffunction waitForPopup(callable $action, array|WaitForPopupOptions $options = []): self
waitForResponse()
ResponseInterfacefunction waitForResponse($url, array|WaitForResponseOptions $options = []): ResponseInterface
waitForRequest()
RequestInterfaceWaits for a request whose URL matches the given Playwright glob. PHP cannot act while this call blocks, so the trigger travels with it: an 'action' entry in $options holds a JavaScript expression the bridge evaluates once the listener is armed.
function waitForRequest(string $url, array|WaitForRequestOptions $options = []): RequestInterface
opener()
?PageInterfaceThe page that opened this one, or null when nothing did.
function opener(): ?PageInterface
requests()
arrayNetwork requests recorded for this page, oldest first. These are snapshots taken by the bridge, not live handles: members that need the Node object, such as response(), return null on them.
function requests(): array
setInputFiles()
selfSet files to an input element with type="file".
function setInputFiles(string $selector, array $files, array|SetInputFilesOptions $options = []): self
mainFrame()
FrameInterfaceGet a handle to the main frame.
function mainFrame(): FrameInterface
frames()
arrayList top-level child frames of the main frame.
function frames(): array
frame()
?FrameInterfaceFind a top-level frame by name or URL.
function frame(array|FrameQueryOptions $options): ?FrameInterface
request()
APIRequestContextInterfaceAPI testing helper associated with this page. This method returns the same instance as browserContext.request() on the page's context.
function request(): APIRequestContextInterface