Documentation ¶
Overview ¶
Package playwright is a library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web automation that is ever-green, capable, reliable and fast.
Index ¶
- Variables
- func Bool(v bool) *bool
- func Float(v float64) *float64
- func Install(options ...*RunOptions) error
- func Int(v int) *int
- func IntSlice(v ...int) *[]int
- func Null() interface{}
- func String(v string) *string
- func StringSlice(v ...string) *[]string
- type APIRequest
- type APIRequestContext
- type APIRequestContextDeleteOptions
- type APIRequestContextDisposeOptions
- type APIRequestContextFetchOptions
- type APIRequestContextGetOptions
- type APIRequestContextHeadOptions
- type APIRequestContextPatchOptions
- type APIRequestContextPostOptions
- type APIRequestContextPutOptions
- type APIRequestNewContextOptions
- type APIResponse
- type APIResponseAssertions
- type AriaRole
- type BindingCall
- type BindingCallFunction
- type BindingSource
- type Browser
- type BrowserCloseOptions
- type BrowserContext
- type BrowserContextClearCookiesOptions
- type BrowserContextCloseOptions
- type BrowserContextExpectConsoleMessageOptions
- type BrowserContextExpectEventOptions
- type BrowserContextExpectPageOptions
- type BrowserContextGrantPermissionsOptions
- type BrowserContextRouteFromHAROptions
- type BrowserContextUnrouteAllOptions
- type BrowserContextWaitForEventOptions
- type BrowserNewContextOptions
- type BrowserNewPageOptions
- type BrowserStartTracingOptions
- type BrowserType
- type BrowserTypeConnectOptions
- type BrowserTypeConnectOverCDPOptions
- type BrowserTypeLaunchOptions
- type BrowserTypeLaunchPersistentContextOptions
- type CDPSession
- type ClientCertificate
- type Clock
- type ClockInstallOptions
- type ColorScheme
- type ConsoleMessage
- type ConsoleMessageLocation
- type Cookie
- type DeviceDescriptor
- type Dialog
- type Download
- type ElementHandle
- type ElementHandleCheckOptions
- type ElementHandleClickOptions
- type ElementHandleDblclickOptions
- type ElementHandleFillOptions
- type ElementHandleHoverOptions
- type ElementHandleInputValueOptions
- type ElementHandlePressOptions
- type ElementHandleScreenshotOptions
- type ElementHandleScrollIntoViewIfNeededOptions
- type ElementHandleSelectOptionOptions
- type ElementHandleSelectTextOptions
- type ElementHandleSetCheckedOptions
- type ElementHandleSetInputFilesOptions
- type ElementHandleTapOptions
- type ElementHandleTypeOptions
- type ElementHandleUncheckOptions
- type ElementHandleWaitForElementStateOptions
- type ElementHandleWaitForSelectorOptions
- type ElementState
- type Error
- type EventEmitter
- type ExposedFunction
- type FileChooser
- type FileChooserSetFilesOptions
- type ForcedColors
- type Frame
- type FrameAddScriptTagOptions
- type FrameAddStyleTagOptions
- type FrameCheckOptions
- type FrameClickOptions
- type FrameDblclickOptions
- type FrameDispatchEventOptions
- type FrameDragAndDropOptions
- type FrameEvalOnSelectorOptions
- type FrameExpectNavigationOptions
- type FrameFillOptions
- type FrameFocusOptions
- type FrameGetAttributeOptions
- type FrameGetByAltTextOptions
- type FrameGetByLabelOptions
- type FrameGetByPlaceholderOptions
- type FrameGetByRoleOptions
- type FrameGetByTextOptions
- type FrameGetByTitleOptions
- type FrameGotoOptions
- type FrameHoverOptions
- type FrameInnerHTMLOptions
- type FrameInnerTextOptions
- type FrameInputValueOptions
- type FrameIsCheckedOptions
- type FrameIsDisabledOptions
- type FrameIsEditableOptions
- type FrameIsEnabledOptions
- type FrameIsHiddenOptions
- type FrameIsVisibleOptions
- type FrameLocator
- type FrameLocatorGetByAltTextOptions
- type FrameLocatorGetByLabelOptions
- type FrameLocatorGetByPlaceholderOptions
- type FrameLocatorGetByRoleOptions
- type FrameLocatorGetByTextOptions
- type FrameLocatorGetByTitleOptions
- type FrameLocatorLocatorOptions
- type FrameLocatorOptions
- type FramePressOptions
- type FrameQuerySelectorOptions
- type FrameSelectOptionOptions
- type FrameSetCheckedOptions
- type FrameSetContentOptions
- type FrameSetInputFilesOptions
- type FrameTapOptions
- type FrameTextContentOptions
- type FrameTypeOptions
- type FrameUncheckOptions
- type FrameWaitForFunctionOptions
- type FrameWaitForLoadStateOptions
- type FrameWaitForSelectorOptions
- type FrameWaitForURLOptions
- type Geolocation
- type HarContentPolicy
- type HarMode
- type HarNotFound
- type HttpCredentials
- type HttpCredentialsSend
- type InputFile
- type JSHandle
- type Keyboard
- type KeyboardModifier
- type KeyboardPressOptions
- type KeyboardTypeOptions
- type LoadState
- type Locator
- type LocatorAssertions
- type LocatorAssertionsToBeAttachedOptions
- type LocatorAssertionsToBeCheckedOptions
- type LocatorAssertionsToBeDisabledOptions
- type LocatorAssertionsToBeEditableOptions
- type LocatorAssertionsToBeEmptyOptions
- type LocatorAssertionsToBeEnabledOptions
- type LocatorAssertionsToBeFocusedOptions
- type LocatorAssertionsToBeHiddenOptions
- type LocatorAssertionsToBeInViewportOptions
- type LocatorAssertionsToBeVisibleOptions
- type LocatorAssertionsToContainTextOptions
- type LocatorAssertionsToHaveAccessibleDescriptionOptions
- type LocatorAssertionsToHaveAccessibleNameOptions
- type LocatorAssertionsToHaveAttributeOptions
- type LocatorAssertionsToHaveCSSOptions
- type LocatorAssertionsToHaveClassOptions
- type LocatorAssertionsToHaveCountOptions
- type LocatorAssertionsToHaveIdOptions
- type LocatorAssertionsToHaveJSPropertyOptions
- type LocatorAssertionsToHaveRoleOptions
- type LocatorAssertionsToHaveTextOptions
- type LocatorAssertionsToHaveValueOptions
- type LocatorAssertionsToHaveValuesOptions
- type LocatorBlurOptions
- type LocatorBoundingBoxOptions
- type LocatorCheckOptions
- type LocatorClearOptions
- type LocatorClickOptions
- type LocatorDblclickOptions
- type LocatorDispatchEventOptions
- type LocatorDragToOptions
- type LocatorElementHandleOptions
- type LocatorEvaluateHandleOptions
- type LocatorEvaluateOptions
- type LocatorFillOptions
- type LocatorFilterOptions
- type LocatorFocusOptions
- type LocatorGetAttributeOptions
- type LocatorGetByAltTextOptions
- type LocatorGetByLabelOptions
- type LocatorGetByPlaceholderOptions
- type LocatorGetByRoleOptions
- type LocatorGetByTextOptions
- type LocatorGetByTitleOptions
- type LocatorHoverOptions
- type LocatorInnerHTMLOptions
- type LocatorInnerTextOptions
- type LocatorInputValueOptions
- type LocatorIsCheckedOptions
- type LocatorIsDisabledOptions
- type LocatorIsEditableOptions
- type LocatorIsEnabledOptions
- type LocatorIsHiddenOptions
- type LocatorIsVisibleOptions
- type LocatorLocatorOptions
- type LocatorPressOptions
- type LocatorPressSequentiallyOptions
- type LocatorScreenshotOptions
- type LocatorScrollIntoViewIfNeededOptions
- type LocatorSelectOptionOptions
- type LocatorSelectTextOptions
- type LocatorSetCheckedOptions
- type LocatorSetInputFilesOptions
- type LocatorTapOptions
- type LocatorTextContentOptions
- type LocatorTypeOptions
- type LocatorUncheckOptions
- type LocatorWaitForOptions
- type Margin
- type Media
- type MixedState
- type Mouse
- type MouseButton
- type MouseClickOptions
- type MouseDblclickOptions
- type MouseDownOptions
- type MouseMoveOptions
- type MouseUpOptions
- type NameValue
- type OptionalCookie
- type OptionalStorageState
- type Origin
- type Page
- type PageAddLocatorHandlerOptions
- type PageAddScriptTagOptions
- type PageAddStyleTagOptions
- type PageAssertions
- type PageAssertionsToHaveTitleOptions
- type PageAssertionsToHaveURLOptions
- type PageCheckOptions
- type PageClickOptions
- type PageCloseOptions
- type PageDblclickOptions
- type PageDispatchEventOptions
- type PageDragAndDropOptions
- type PageEmulateMediaOptions
- type PageEvalOnSelectorOptions
- type PageExpectConsoleMessageOptions
- type PageExpectDownloadOptions
- type PageExpectEventOptions
- type PageExpectFileChooserOptions
- type PageExpectNavigationOptions
- type PageExpectPopupOptions
- type PageExpectRequestFinishedOptions
- type PageExpectRequestOptions
- type PageExpectResponseOptions
- type PageExpectWebSocketOptions
- type PageExpectWorkerOptions
- type PageFillOptions
- type PageFocusOptions
- type PageFrameOptions
- type PageGetAttributeOptions
- type PageGetByAltTextOptions
- type PageGetByLabelOptions
- type PageGetByPlaceholderOptions
- type PageGetByRoleOptions
- type PageGetByTextOptions
- type PageGetByTitleOptions
- type PageGoBackOptions
- type PageGoForwardOptions
- type PageGotoOptions
- type PageHoverOptions
- type PageInnerHTMLOptions
- type PageInnerTextOptions
- type PageInputValueOptions
- type PageIsCheckedOptions
- type PageIsDisabledOptions
- type PageIsEditableOptions
- type PageIsEnabledOptions
- type PageIsHiddenOptions
- type PageIsVisibleOptions
- type PageLocatorOptions
- type PagePdfOptions
- type PagePressOptions
- type PageQuerySelectorOptions
- type PageReloadOptions
- type PageRouteFromHAROptions
- type PageScreenshotOptions
- type PageSelectOptionOptions
- type PageSetCheckedOptions
- type PageSetContentOptions
- type PageSetInputFilesOptions
- type PageTapOptions
- type PageTextContentOptions
- type PageTypeOptions
- type PageUncheckOptions
- type PageUnrouteAllOptions
- type PageWaitForEventOptions
- type PageWaitForFunctionOptions
- type PageWaitForLoadStateOptions
- type PageWaitForSelectorOptions
- type PageWaitForURLOptions
- type Playwright
- type PlaywrightAssertions
- type PlaywrightDriver
- type Position
- type Proxy
- type RecordVideo
- type Rect
- type ReducedMotion
- type Request
- type RequestSizesResult
- type RequestTiming
- type Response
- type ResponseSecurityDetailsResult
- type ResponseServerAddrResult
- type Route
- type RouteContinueOptions
- type RouteFallbackOptions
- type RouteFetchOptions
- type RouteFromHarUpdateContentPolicy
- type RouteFulfillOptions
- type RunOptions
- type SameSiteAttribute
- type ScreenshotAnimations
- type ScreenshotCaret
- type ScreenshotScale
- type ScreenshotType
- type Script
- type SelectOptionValues
- type Selectors
- type SelectorsRegisterOptions
- type ServiceWorkerPolicy
- type Size
- type StorageState
- type Touchscreen
- type Tracing
- type TracingStartChunkOptions
- type TracingStartOptions
- type UnrouteBehavior
- type Video
- type WaitForSelectorState
- type WaitUntilState
- type WebError
- type WebSocket
- type WebSocketExpectEventOptions
- type WebSocketWaitForEventOptions
- type Worker
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPlaywright wraps all Playwright errors. // - Use errors.Is to check if the error is a Playwright error. // - Use errors.As to cast an error to [Error] if you want to access "Stack". ErrPlaywright = errors.New("playwright") // ErrTargetClosed usually wraps a reason. ErrTargetClosed = errors.New("target closed") // ErrTimeout wraps timeout errors. It can be either Playwright TimeoutError or client timeout. ErrTimeout = errors.New("timeout") )
var ( MixedStateOn *MixedState = getMixedState("On") MixedStateOff = getMixedState("Off") MixedStateMixed = getMixedState("Mixed") )
var ( ElementStateVisible *ElementState = getElementState("visible") ElementStateHidden = getElementState("hidden") ElementStateStable = getElementState("stable") ElementStateEnabled = getElementState("enabled") ElementStateDisabled = getElementState("disabled") ElementStateEditable = getElementState("editable") )
var ( AriaRoleAlert *AriaRole = getAriaRole("alert") AriaRoleAlertdialog = getAriaRole("alertdialog") AriaRoleApplication = getAriaRole("application") AriaRoleArticle = getAriaRole("article") AriaRoleBanner = getAriaRole("banner") AriaRoleBlockquote = getAriaRole("blockquote") AriaRoleButton = getAriaRole("button") AriaRoleCaption = getAriaRole("caption") AriaRoleCell = getAriaRole("cell") AriaRoleCheckbox = getAriaRole("checkbox") AriaRoleCode = getAriaRole("code") AriaRoleColumnheader = getAriaRole("columnheader") AriaRoleCombobox = getAriaRole("combobox") AriaRoleComplementary = getAriaRole("complementary") AriaRoleContentinfo = getAriaRole("contentinfo") AriaRoleDefinition = getAriaRole("definition") AriaRoleDeletion = getAriaRole("deletion") AriaRoleDialog = getAriaRole("dialog") AriaRoleDirectory = getAriaRole("directory") AriaRoleDocument = getAriaRole("document") AriaRoleEmphasis = getAriaRole("emphasis") AriaRoleFeed = getAriaRole("feed") AriaRoleFigure = getAriaRole("figure") AriaRoleForm = getAriaRole("form") AriaRoleGeneric = getAriaRole("generic") AriaRoleGrid = getAriaRole("grid") AriaRoleGridcell = getAriaRole("gridcell") AriaRoleGroup = getAriaRole("group") AriaRoleHeading = getAriaRole("heading") AriaRoleImg = getAriaRole("img") AriaRoleInsertion = getAriaRole("insertion") AriaRoleLink = getAriaRole("link") AriaRoleList = getAriaRole("list") AriaRoleListbox = getAriaRole("listbox") AriaRoleListitem = getAriaRole("listitem") AriaRoleLog = getAriaRole("log") AriaRoleMain = getAriaRole("main") AriaRoleMarquee = getAriaRole("marquee") AriaRoleMath = getAriaRole("math") AriaRoleMeter = getAriaRole("meter") AriaRoleMenu = getAriaRole("menu") AriaRoleMenubar = getAriaRole("menubar") AriaRoleMenuitem = getAriaRole("menuitem") AriaRoleMenuitemcheckbox = getAriaRole("menuitemcheckbox") AriaRoleMenuitemradio = getAriaRole("menuitemradio") AriaRoleNone = getAriaRole("none") AriaRoleNote = getAriaRole("note") AriaRoleOption = getAriaRole("option") AriaRoleParagraph = getAriaRole("paragraph") AriaRolePresentation = getAriaRole("presentation") AriaRoleProgressbar = getAriaRole("progressbar") AriaRoleRadio = getAriaRole("radio") AriaRoleRadiogroup = getAriaRole("radiogroup") AriaRoleRegion = getAriaRole("region") AriaRoleRow = getAriaRole("row") AriaRoleRowgroup = getAriaRole("rowgroup") AriaRoleRowheader = getAriaRole("rowheader") AriaRoleScrollbar = getAriaRole("scrollbar") AriaRoleSearch = getAriaRole("search") AriaRoleSearchbox = getAriaRole("searchbox") AriaRoleSeparator = getAriaRole("separator") AriaRoleSlider = getAriaRole("slider") AriaRoleStatus = getAriaRole("status") AriaRoleStrong = getAriaRole("strong") AriaRoleSubscript = getAriaRole("subscript") AriaRoleSuperscript = getAriaRole("superscript") AriaRoleSwitch = getAriaRole("switch") AriaRoleTab = getAriaRole("tab") AriaRoleTable = getAriaRole("table") AriaRoleTablist = getAriaRole("tablist") AriaRoleTabpanel = getAriaRole("tabpanel") AriaRoleTerm = getAriaRole("term") AriaRoleTextbox = getAriaRole("textbox") AriaRoleTime = getAriaRole("time") AriaRoleTimer = getAriaRole("timer") AriaRoleToolbar = getAriaRole("toolbar") AriaRoleTooltip = getAriaRole("tooltip") AriaRoleTree = getAriaRole("tree") AriaRoleTreegrid = getAriaRole("treegrid") AriaRoleTreeitem = getAriaRole("treeitem") )
var ( ColorSchemeLight *ColorScheme = getColorScheme("light") ColorSchemeDark = getColorScheme("dark") ColorSchemeNoPreference = getColorScheme("no-preference") ColorSchemeNoOverride = getColorScheme("no-override") )
var ( ForcedColorsActive *ForcedColors = getForcedColors("active") ForcedColorsNone = getForcedColors("none") ForcedColorsNoOverride = getForcedColors("no-override") )
var ( HarContentPolicyOmit *HarContentPolicy = getHarContentPolicy("omit") HarContentPolicyEmbed = getHarContentPolicy("embed") HarContentPolicyAttach = getHarContentPolicy("attach") )
var ( ReducedMotionReduce *ReducedMotion = getReducedMotion("reduce") ReducedMotionNoPreference = getReducedMotion("no-preference") ReducedMotionNoOverride = getReducedMotion("no-override") )
var ( SameSiteAttributeStrict *SameSiteAttribute = getSameSiteAttribute("Strict") SameSiteAttributeLax = getSameSiteAttribute("Lax") SameSiteAttributeNone = getSameSiteAttribute("None") )
var ( UnrouteBehaviorWait *UnrouteBehavior = getUnrouteBehavior("wait") UnrouteBehaviorIgnoreErrors = getUnrouteBehavior("ignoreErrors") UnrouteBehaviorDefault = getUnrouteBehavior("default") )
var ( MouseButtonLeft *MouseButton = getMouseButton("left") MouseButtonRight = getMouseButton("right") MouseButtonMiddle = getMouseButton("middle") )
var ( KeyboardModifierAlt *KeyboardModifier = getKeyboardModifier("Alt") KeyboardModifierControl = getKeyboardModifier("Control") KeyboardModifierControlOrMeta = getKeyboardModifier("ControlOrMeta") KeyboardModifierMeta = getKeyboardModifier("Meta") KeyboardModifierShift = getKeyboardModifier("Shift") )
var ( WaitForSelectorStateAttached *WaitForSelectorState = getWaitForSelectorState("attached") WaitForSelectorStateDetached = getWaitForSelectorState("detached") WaitForSelectorStateVisible = getWaitForSelectorState("visible") WaitForSelectorStateHidden = getWaitForSelectorState("hidden") )
var ( WaitUntilStateLoad *WaitUntilState = getWaitUntilState("load") WaitUntilStateDomcontentloaded = getWaitUntilState("domcontentloaded") WaitUntilStateNetworkidle = getWaitUntilState("networkidle") WaitUntilStateCommit = getWaitUntilState("commit") )
var ( LoadStateLoad *LoadState = getLoadState("load") LoadStateDomcontentloaded = getLoadState("domcontentloaded") LoadStateNetworkidle = getLoadState("networkidle") )
var ( MediaScreen *Media = getMedia("screen") MediaPrint = getMedia("print") MediaNoOverride = getMedia("no-override") )
var ErrInputFilesSizeExceeded = errors.New("Cannot set buffer larger than 50Mb, please write it to a file and pass its path instead.")
var (
ErrLocatorNotSameFrame = errors.New("inner 'has' or 'hasNot' locator must belong to the same frame")
)
Functions ¶
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func Float ¶
Float is a helper routine that allocates a new float64 value to store v and returns a pointer to it.
func Install ¶
func Install(options ...*RunOptions) error
Install does download the driver and the browsers.
Use this before playwright.Run() or use playwright cli to install the driver and browsers
func Int ¶
Int is a helper routine that allocates a new int32 value to store v and returns a pointer to it.
func IntSlice ¶
IntSlice is a helper routine that allocates a new IntSlice value to store v and returns a pointer to it.
func Null ¶
func Null() interface{}
Null will be used in certain scenarios where a strict nil pointer check is not possible
func String ¶
String is a helper routine that allocates a new string value to store v and returns a pointer to it.
func StringSlice ¶
StringSlice is a helper routine that allocates a new StringSlice value to store v and returns a pointer to it.
Types ¶
type APIRequest ¶ added in v0.3500.0
type APIRequest interface { // Creates new instances of [APIRequestContext]. NewContext(options ...APIRequestNewContextOptions) (APIRequestContext, error) }
Exposes API that can be used for the Web API testing. This class is used for creating APIRequestContext instance which in turn can be used for sending web requests. An instance of this class can be obtained via [Playwright.Request]. For more information see APIRequestContext.
type APIRequestContext ¶ added in v0.3500.0
type APIRequestContext interface { // Sends HTTP(S) [DELETE] request and returns its // response. The method will populate request cookies from the context and update context cookies from the response. // The method will automatically follow redirects. // // url: Target URL. // // [DELETE]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE Delete(url string, options ...APIRequestContextDeleteOptions) (APIResponse, error) // All responses returned by [APIRequestContext.Get] and similar methods are stored in the memory, so that you can // later call [APIResponse.Body].This method discards all its resources, calling any method on disposed // [APIRequestContext] will throw an exception. Dispose(options ...APIRequestContextDisposeOptions) error // Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and // update context cookies from the response. The method will automatically follow redirects. // // urlOrRequest: Target URL or Request to get all parameters from. Fetch(urlOrRequest interface{}, options ...APIRequestContextFetchOptions) (APIResponse, error) // Sends HTTP(S) [GET] request and returns its // response. The method will populate request cookies from the context and update context cookies from the response. // The method will automatically follow redirects. // // url: Target URL. // // [GET]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET Get(url string, options ...APIRequestContextGetOptions) (APIResponse, error) // Sends HTTP(S) [HEAD] request and returns its // response. The method will populate request cookies from the context and update context cookies from the response. // The method will automatically follow redirects. // // url: Target URL. // // [HEAD]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD Head(url string, options ...APIRequestContextHeadOptions) (APIResponse, error) // Sends HTTP(S) [PATCH] request and returns its // response. The method will populate request cookies from the context and update context cookies from the response. // The method will automatically follow redirects. // // url: Target URL. // // [PATCH]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH Patch(url string, options ...APIRequestContextPatchOptions) (APIResponse, error) // Sends HTTP(S) [POST] request and returns its // response. The method will populate request cookies from the context and update context cookies from the response. // The method will automatically follow redirects. // // url: Target URL. // // [POST]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST Post(url string, options ...APIRequestContextPostOptions) (APIResponse, error) // Sends HTTP(S) [PUT] request and returns its // response. The method will populate request cookies from the context and update context cookies from the response. // The method will automatically follow redirects. // // url: Target URL. // // [PUT]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT Put(url string, options ...APIRequestContextPutOptions) (APIResponse, error) // Returns storage state for this request context, contains current cookies and local storage snapshot if it was // passed to the constructor. StorageState(path ...string) (*StorageState, error) }
This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare environment or the service to your e2e test. Each Playwright browser context has associated with it APIRequestContext instance which shares cookie storage with the browser context and can be accessed via [BrowserContext.Request] or [Page.Request]. It is also possible to create a new APIRequestContext instance manually by calling [APIRequest.NewContext]. **Cookie management** APIRequestContext returned by [BrowserContext.Request] and [Page.Request] shares cookie storage with the corresponding BrowserContext. Each API request will have `Cookie` header populated with the values from the browser context. If the API response contains `Set-Cookie` header it will automatically update BrowserContext cookies and requests made from the page will pick them up. This means that if you log in using this API, your e2e test will be logged in and vice versa. If you want API requests to not interfere with the browser cookies you should create a new APIRequestContext by calling [APIRequest.NewContext]. Such `APIRequestContext` object will have its own isolated cookie storage.
type APIRequestContextDeleteOptions ¶ added in v0.3500.0
type APIRequestContextDeleteOptions struct { // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` // header will be set to `application/octet-stream` if not explicitly set. Data interface{} `json:"data"` // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status // codes. FailOnStatusCode *bool `json:"failOnStatusCode"` // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent // as this request body. If this parameter is specified `content-type` header will be set to // `application/x-www-form-urlencoded` unless explicitly provided. Form interface{} `json:"form"` // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by // it. Headers map[string]string `json:"headers"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless // explicitly provided. File values can be passed either as // [`fs.ReadStream`] or as file-like object containing file // name, mime-type and its content. // // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream Multipart interface{} `json:"multipart"` // Query parameters to be sent with the URL. Params map[string]interface{} `json:"params"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type APIRequestContextDisposeOptions ¶ added in v0.4501.0
type APIRequestContextDisposeOptions struct { // The reason to be reported to the operations interrupted by the context disposal. Reason *string `json:"reason"` }
type APIRequestContextFetchOptions ¶ added in v0.3500.0
type APIRequestContextFetchOptions struct { // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` // header will be set to `application/octet-stream` if not explicitly set. Data interface{} `json:"data"` // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status // codes. FailOnStatusCode *bool `json:"failOnStatusCode"` // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent // as this request body. If this parameter is specified `content-type` header will be set to // `application/x-www-form-urlencoded` unless explicitly provided. Form interface{} `json:"form"` // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by // it. Headers map[string]string `json:"headers"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // If set changes the fetch method (e.g. [PUT] or // [POST]. If not specified, GET method is used. // // [PUT]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT // [POST]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) Method *string `json:"method"` // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless // explicitly provided. File values can be passed either as // [`fs.ReadStream`] or as file-like object containing file // name, mime-type and its content. // // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream Multipart interface{} `json:"multipart"` // Query parameters to be sent with the URL. Params map[string]interface{} `json:"params"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type APIRequestContextGetOptions ¶ added in v0.3500.0
type APIRequestContextGetOptions struct { // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` // header will be set to `application/octet-stream` if not explicitly set. Data interface{} `json:"data"` // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status // codes. FailOnStatusCode *bool `json:"failOnStatusCode"` // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent // as this request body. If this parameter is specified `content-type` header will be set to // `application/x-www-form-urlencoded` unless explicitly provided. Form interface{} `json:"form"` // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by // it. Headers map[string]string `json:"headers"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless // explicitly provided. File values can be passed either as // [`fs.ReadStream`] or as file-like object containing file // name, mime-type and its content. // // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream Multipart interface{} `json:"multipart"` // Query parameters to be sent with the URL. Params map[string]interface{} `json:"params"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type APIRequestContextHeadOptions ¶ added in v0.3500.0
type APIRequestContextHeadOptions struct { // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` // header will be set to `application/octet-stream` if not explicitly set. Data interface{} `json:"data"` // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status // codes. FailOnStatusCode *bool `json:"failOnStatusCode"` // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent // as this request body. If this parameter is specified `content-type` header will be set to // `application/x-www-form-urlencoded` unless explicitly provided. Form interface{} `json:"form"` // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by // it. Headers map[string]string `json:"headers"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless // explicitly provided. File values can be passed either as // [`fs.ReadStream`] or as file-like object containing file // name, mime-type and its content. // // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream Multipart interface{} `json:"multipart"` // Query parameters to be sent with the URL. Params map[string]interface{} `json:"params"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type APIRequestContextPatchOptions ¶ added in v0.3500.0
type APIRequestContextPatchOptions struct { // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` // header will be set to `application/octet-stream` if not explicitly set. Data interface{} `json:"data"` // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status // codes. FailOnStatusCode *bool `json:"failOnStatusCode"` // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent // as this request body. If this parameter is specified `content-type` header will be set to // `application/x-www-form-urlencoded` unless explicitly provided. Form interface{} `json:"form"` // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by // it. Headers map[string]string `json:"headers"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless // explicitly provided. File values can be passed either as // [`fs.ReadStream`] or as file-like object containing file // name, mime-type and its content. // // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream Multipart interface{} `json:"multipart"` // Query parameters to be sent with the URL. Params map[string]interface{} `json:"params"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type APIRequestContextPostOptions ¶ added in v0.3500.0
type APIRequestContextPostOptions struct { // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` // header will be set to `application/octet-stream` if not explicitly set. Data interface{} `json:"data"` // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status // codes. FailOnStatusCode *bool `json:"failOnStatusCode"` // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent // as this request body. If this parameter is specified `content-type` header will be set to // `application/x-www-form-urlencoded` unless explicitly provided. Form interface{} `json:"form"` // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by // it. Headers map[string]string `json:"headers"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless // explicitly provided. File values can be passed either as // [`fs.ReadStream`] or as file-like object containing file // name, mime-type and its content. // // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream Multipart interface{} `json:"multipart"` // Query parameters to be sent with the URL. Params map[string]interface{} `json:"params"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type APIRequestContextPutOptions ¶ added in v0.3500.0
type APIRequestContextPutOptions struct { // Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string // and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` // header will be set to `application/octet-stream` if not explicitly set. Data interface{} `json:"data"` // Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status // codes. FailOnStatusCode *bool `json:"failOnStatusCode"` // Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent // as this request body. If this parameter is specified `content-type` header will be set to // `application/x-www-form-urlencoded` unless explicitly provided. Form interface{} `json:"form"` // Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by // it. Headers map[string]string `json:"headers"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this // request body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless // explicitly provided. File values can be passed either as // [`fs.ReadStream`] or as file-like object containing file // name, mime-type and its content. // // [`fs.ReadStream`]: https://nodejs.org/api/fs.html#fs_class_fs_readstream Multipart interface{} `json:"multipart"` // Query parameters to be sent with the URL. Params map[string]interface{} `json:"params"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type APIRequestNewContextOptions ¶ added in v0.3500.0
type APIRequestNewContextOptions struct { // Methods like [APIRequestContext.Get] take the base URL into consideration by using the // [`URL()`] constructor for building the corresponding URL. // Examples: // - baseURL: `http://localhost:3000` and sending request to `/bar.html` results in `http://localhost:3000/bar.html` // - baseURL: `http://localhost:3000/foo/` and sending request to `./bar.html` results in // `http://localhost:3000/foo/bar.html` // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in // `http://localhost:3000/bar.html` // // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL BaseURL *string `json:"baseURL"` // TLS Client Authentication allows the server to request a client certificate and verify it. // // # Details // // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided // with an exact match to the request origin that the certificate is valid for. // **NOTE** Using Client Certificates in combination with Proxy Servers is not supported. // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it // work by replacing `localhost` with `local.playwright`. ClientCertificates []ClientCertificate `json:"clientCertificates"` // An object containing additional HTTP headers to be sent with every request. Defaults to none. ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` // Credentials for [HTTP authentication]. If no // origin is specified, the username and password are sent to any servers upon unauthorized responses. // // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication HttpCredentials *HttpCredentials `json:"httpCredentials"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Network proxy settings. Proxy *Proxy `json:"proxy"` // Populates context with given storage state. This option can be used to initialize context with logged-in // information obtained via [BrowserContext.StorageState] or [APIRequestContext.StorageState]. Either a path to the // file with saved storage, or the value returned by one of [BrowserContext.StorageState] or // [APIRequestContext.StorageState] methods. StorageState *StorageState `json:"storageState"` // Populates context with given storage state. This option can be used to initialize context with logged-in // information obtained via [BrowserContext.StorageState]. Path to the file with saved storage state. StorageStatePath *string `json:"storageStatePath"` // Maximum time in milliseconds to wait for the response. Defaults to `30000` (30 seconds). Pass `0` to disable // timeout. Timeout *float64 `json:"timeout"` // Specific user agent to use in this context. UserAgent *string `json:"userAgent"` }
type APIResponse ¶ added in v0.3500.0
type APIResponse interface { // Returns the buffer with response body. Body() ([]byte, error) // Disposes the body of this response. If not called then the body will stay in memory until the context closes. Dispose() error // An object with all the response HTTP headers associated with this response. Headers() map[string]string // An array with all the response HTTP headers associated with this response. Header names are not lower-cased. // Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times. HeadersArray() []NameValue // Returns the JSON representation of response body. // This method will throw if the response body is not parsable via `JSON.parse`. JSON(v interface{}) error // Contains a boolean stating whether the response was successful (status in the range 200-299) or not. Ok() bool // Contains the status code of the response (e.g., 200 for a success). Status() int // Contains the status text of the response (e.g. usually an "OK" for a success). StatusText() string // Returns the text representation of response body. Text() (string, error) // Contains the URL of the response. URL() string }
APIResponse class represents responses returned by [APIRequestContext.Get] and similar methods.
type APIResponseAssertions ¶ added in v0.3500.0
type APIResponseAssertions interface { // Makes the assertion check for the opposite condition. For example, this code tests that the response status is not // successful: Not() APIResponseAssertions // Ensures the response status code is within `200..299` range. ToBeOK() error }
The APIResponseAssertions class provides assertion methods that can be used to make assertions about the APIResponse in the tests.
type BindingCall ¶
type BindingCall interface {
Call(f BindingCallFunction)
}
type BindingCallFunction ¶
type BindingCallFunction func(source *BindingSource, args ...interface{}) interface{}
BindingCallFunction represents the func signature of an exposed binding call func
type BindingSource ¶
type BindingSource struct { Context BrowserContext Page Page Frame Frame }
BindingSource is the value passed to a binding call execution
type Browser ¶
type Browser interface { EventEmitter // Emitted when Browser gets disconnected from the browser application. This might happen because of one of the // following: // - Browser application is closed or crashed. // - The [Browser.Close] method was called. OnDisconnected(fn func(Browser)) // Get the browser type (chromium, firefox or webkit) that the browser belongs to. BrowserType() BrowserType // In case this browser is obtained using [BrowserType.Launch], closes the browser and all of its pages (if any were // opened). // In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from // the browser server. // **NOTE** This is similar to force quitting the browser. Therefore, you should call [BrowserContext.Close] on any // [BrowserContext]'s you explicitly created earlier with [Browser.NewContext] **before** calling [Browser.Close]. // The [Browser] object itself is considered to be disposed and cannot be used anymore. Close(options ...BrowserCloseOptions) error // Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts. Contexts() []BrowserContext // Indicates that the browser is connected. IsConnected() bool // **NOTE** CDP Sessions are only supported on Chromium-based browsers. // Returns the newly created browser session. NewBrowserCDPSession() (CDPSession, error) // Creates a new browser context. It won't share cookies/cache with other browser contexts. // **NOTE** If directly using this method to create [BrowserContext]s, it is best practice to explicitly close the // returned context via [BrowserContext.Close] when your code is done with the [BrowserContext], and before calling // [Browser.Close]. This will ensure the `context` is closed gracefully and any artifacts—like HARs and videos—are // fully flushed and saved. NewContext(options ...BrowserNewContextOptions) (BrowserContext, error) // Creates a new page in a new browser context. Closing this page will close the context as well. // This is a convenience API that should only be used for the single-page scenarios and short snippets. Production // code and testing frameworks should explicitly create [Browser.NewContext] followed by the [BrowserContext.NewPage] // to control their exact life times. NewPage(options ...BrowserNewPageOptions) (Page, error) // **NOTE** This API controls // [Chromium Tracing] which is a low-level // chromium-specific debugging tool. API to control [Playwright Tracing] could be found // [here]. // You can use [Browser.StartTracing] and [Browser.StopTracing] to create a trace file that can be opened in Chrome // DevTools performance panel. // // [Chromium Tracing]: https://www.chromium.org/developers/how-tos/trace-event-profiling-tool // [Playwright Tracing]: ../trace-viewer // [here]: ./class-tracing StartTracing(options ...BrowserStartTracingOptions) error // **NOTE** This API controls // [Chromium Tracing] which is a low-level // chromium-specific debugging tool. API to control [Playwright Tracing] could be found // [here]. // Returns the buffer with trace data. // // [Chromium Tracing]: https://www.chromium.org/developers/how-tos/trace-event-profiling-tool // [Playwright Tracing]: ../trace-viewer // [here]: ./class-tracing StopTracing() ([]byte, error) // Returns the browser version. Version() string }
A Browser is created via [BrowserType.Launch]. An example of using a Browser to create a Page:
type BrowserCloseOptions ¶ added in v0.4001.0
type BrowserCloseOptions struct { // The reason to be reported to the operations interrupted by the browser closure. Reason *string `json:"reason"` }
type BrowserContext ¶
type BrowserContext interface { EventEmitter // **NOTE** Only works with Chromium browser's persistent context. // Emitted when new background page is created in the context. OnBackgroundPage(fn func(Page)) // Playwright has ability to mock clock and passage of time. Clock() Clock // Emitted when Browser context gets closed. This might happen because of one of the following: // - Browser context is closed. // - Browser application is closed or crashed. // - The [Browser.Close] method was called. OnClose(fn func(BrowserContext)) // Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. // The arguments passed into `console.log` and the page are available on the [ConsoleMessage] event handler argument. OnConsole(fn func(ConsoleMessage)) // Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** // either [Dialog.Accept] or [Dialog.Dismiss] the dialog - otherwise the page will // [freeze] waiting for the dialog, // and actions like click will never finish. // // [freeze]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking OnDialog(fn func(Dialog)) // The event is emitted when a new Page is created in the BrowserContext. The page may still be loading. The event // will also fire for popup pages. See also [Page.OnPopup] to receive events about popups relevant to a specific page. // The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a // popup with `window.open('http://example.com')`, this event will fire when the network request to // "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen // to this network request, use [BrowserContext.Route] and [BrowserContext.OnRequest] respectively instead of similar // methods on the [Page]. // **NOTE** Use [Page.WaitForLoadState] to wait until the page gets to a particular state (you should not need it in // most cases). OnPage(fn func(Page)) // Emitted when exception is unhandled in any of the pages in this context. To listen for errors from a particular // page, use [Page.OnPageError] instead. OnWebError(fn func(WebError)) // Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To // only listen for requests from a particular page, use [Page.OnRequest]. // In order to intercept and mutate requests, see [BrowserContext.Route] or [Page.Route]. OnRequest(fn func(Request)) // Emitted when a request fails, for example by timing out. To only listen for failed requests from a particular page, // use [Page.OnRequestFailed]. // **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request // will complete with [BrowserContext.OnRequestFinished] event and not with [BrowserContext.OnRequestFailed]. OnRequestFailed(fn func(Request)) // Emitted when a request finishes successfully after downloading the response body. For a successful response, the // sequence of events is `request`, `response` and `requestfinished`. To listen for successful requests from a // particular page, use [Page.OnRequestFinished]. OnRequestFinished(fn func(Request)) // Emitted when [response] status and headers are received for a request. For a successful response, the sequence of // events is `request`, `response` and `requestfinished`. To listen for response events from a particular page, use // [Page.OnResponse]. OnResponse(fn func(Response)) // Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies // can be obtained via [BrowserContext.Cookies]. AddCookies(cookies []OptionalCookie) error // Adds a script which would be evaluated in one of the following scenarios: // - Whenever a page is created in the browser context or is navigated. // - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is // evaluated in the context of the newly attached frame. // The script is evaluated after the document was created but before any of its scripts were run. This is useful to // amend the JavaScript environment, e.g. to seed `Math.random`. // // script: Script to be evaluated in all pages in the browser context. AddInitScript(script Script) error // **NOTE** Background pages are only supported on Chromium-based browsers. // All existing background pages in the context. BackgroundPages() []Page // Returns the browser instance of the context. If it was launched as a persistent context null gets returned. Browser() Browser // Removes cookies from context. Accepts optional filter. ClearCookies(options ...BrowserContextClearCookiesOptions) error // Clears all permission overrides for the browser context. ClearPermissions() error // Closes the browser context. All the pages that belong to the browser context will be closed. // **NOTE** The default browser context cannot be closed. Close(options ...BrowserContextCloseOptions) error // If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those // URLs are returned. Cookies(urls ...string) ([]Cookie, error) // The method adds a function called “name” on the `window` object of every frame in every page in the context. When // called, the function executes “callback” and returns a [Promise] which resolves to the return value of “callback”. // If the “callback” returns a [Promise], it will be awaited. // The first argument of the “callback” function contains information about the caller: `{ browserContext: // BrowserContext, page: Page, frame: Frame }`. // See [Page.ExposeBinding] for page-only version. // // 1. name: Name of the function on the window object. // 2. binding: Callback function that will be called in the Playwright's context. ExposeBinding(name string, binding BindingCallFunction, handle ...bool) error // The method adds a function called “name” on the `window` object of every frame in every page in the context. When // called, the function executes “callback” and returns a [Promise] which resolves to the return value of “callback”. // If the “callback” returns a [Promise], it will be awaited. // See [Page.ExposeFunction] for page-only version. // // 1. name: Name of the function on the window object. // 2. binding: Callback function that will be called in the Playwright's context. ExposeFunction(name string, binding ExposedFunction) error // Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if // specified. // // permissions: A permission or an array of permissions to grant. Permissions can be one of the following values: // - `'accelerometer'` // - `'accessibility-events'` // - `'ambient-light-sensor'` // - `'background-sync'` // - `'camera'` // - `'clipboard-read'` // - `'clipboard-write'` // - `'geolocation'` // - `'gyroscope'` // - `'magnetometer'` // - `'microphone'` // - `'midi-sysex'` (system-exclusive midi) // - `'midi'` // - `'notifications'` // - `'payment-handler'` // - `'storage-access'` GrantPermissions(permissions []string, options ...BrowserContextGrantPermissionsOptions) error // **NOTE** CDP sessions are only supported on Chromium-based browsers. // Returns the newly created session. // // page: Target to create new session for. For backwards-compatibility, this parameter is named `page`, but it can be a // `Page` or `Frame` type. NewCDPSession(page interface{}) (CDPSession, error) // Creates a new page in the browser context. NewPage() (Page, error) // Returns all open pages in the context. Pages() []Page // API testing helper associated with this context. Requests made with this API will use context cookies. Request() APIRequestContext // Routing provides the capability to modify network requests that are made by any page in the browser context. Once // route is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted. // **NOTE** [BrowserContext.Route] will not intercept requests intercepted by Service Worker. See // [this] issue. We recommend disabling Service Workers when // using request interception by setting “Browser.newContext.serviceWorkers” to `block`. // // 1. url: A glob pattern, regex pattern or predicate receiving [URL] to match while routing. When a “baseURL” via the context // options was provided and the passed URL is a path, it gets merged via the // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. // 2. handler: handler function to route the request. // // [this]: https://github.com/microsoft/playwright/issues/1090 Route(url interface{}, handler routeHandler, times ...int) error // If specified the network requests that are made in the context will be served from the HAR file. Read more about // [Replaying from HAR]. // Playwright will not serve requests intercepted by Service Worker from the HAR file. See // [this] issue. We recommend disabling Service Workers when // using request interception by setting “Browser.newContext.serviceWorkers” to `block`. // // har: Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a // relative path, then it is resolved relative to the current working directory. // // [Replaying from HAR]: https://playwright.dev/docs/mock#replaying-from-har // [this]: https://github.com/microsoft/playwright/issues/1090 RouteFromHAR(har string, options ...BrowserContextRouteFromHAROptions) error // **NOTE** Service workers are only supported on Chromium-based browsers. // All existing service workers in the context. ServiceWorkers() []Worker // - [Page.GoBack] // - [Page.GoForward] // - [Page.Goto] // - [Page.Reload] // - [Page.SetContent] // - [Page.ExpectNavigation] // **NOTE** [Page.SetDefaultNavigationTimeout] and [Page.SetDefaultTimeout] take priority over // [BrowserContext.SetDefaultNavigationTimeout]. // // timeout: Maximum navigation time in milliseconds SetDefaultNavigationTimeout(timeout float64) // This setting will change the default maximum time for all the methods accepting “timeout” option. // **NOTE** [Page.SetDefaultNavigationTimeout], [Page.SetDefaultTimeout] and // [BrowserContext.SetDefaultNavigationTimeout] take priority over [BrowserContext.SetDefaultTimeout]. // // timeout: Maximum time in milliseconds SetDefaultTimeout(timeout float64) // The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are // merged with page-specific extra HTTP headers set with [Page.SetExtraHTTPHeaders]. If page overrides a particular // header, page-specific header value will be used instead of the browser context header value. // **NOTE** [BrowserContext.SetExtraHTTPHeaders] does not guarantee the order of headers in the outgoing requests. // // headers: An object containing additional HTTP headers to be sent with every request. All header values must be strings. SetExtraHTTPHeaders(headers map[string]string) error // Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable. SetGeolocation(geolocation *Geolocation) error // // offline: Whether to emulate network being offline for the browser context. SetOffline(offline bool) error // Returns storage state for this browser context, contains current cookies and local storage snapshot. StorageState(path ...string) (*StorageState, error) Tracing() Tracing // Removes all routes created with [BrowserContext.Route] and [BrowserContext.RouteFromHAR]. UnrouteAll(options ...BrowserContextUnrouteAllOptions) error // Removes a route created with [BrowserContext.Route]. When “handler” is not specified, removes all routes for the // “url”. // // 1. url: A glob pattern, regex pattern or predicate receiving [URL] used to register a routing with [BrowserContext.Route]. // 2. handler: Optional handler function used to register a routing with [BrowserContext.Route]. Unroute(url interface{}, handler ...routeHandler) error // Performs action and waits for a [ConsoleMessage] to be logged by in the pages in the context. If predicate is // provided, it passes [ConsoleMessage] value into the `predicate` function and waits for `predicate(message)` to // return a truthy value. Will throw an error if the page is closed before the [BrowserContext.OnConsole] event is // fired. ExpectConsoleMessage(cb func() error, options ...BrowserContextExpectConsoleMessageOptions) (ConsoleMessage, error) // Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy // value. Will throw an error if the context closes before the event is fired. Returns the event data value. // // event: Event name, same one would pass into `browserContext.on(event)`. ExpectEvent(event string, cb func() error, options ...BrowserContextExpectEventOptions) (interface{}, error) // Performs action and waits for a new [Page] to be created in the context. If predicate is provided, it passes [Page] // value into the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error // if the context closes before new [Page] is created. ExpectPage(cb func() error, options ...BrowserContextExpectPageOptions) (Page, error) // **NOTE** In most cases, you should use [BrowserContext.ExpectEvent]. // Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function // and waits for `predicate(event)` to return a truthy value. Will throw an error if the browser context is closed // before the `event` is fired. // // event: Event name, same one typically passed into `*.on(event)`. WaitForEvent(event string, options ...BrowserContextWaitForEventOptions) (interface{}, error) }
BrowserContexts provide a way to operate multiple independent browser sessions. If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser context. Playwright allows creating isolated non-persistent browser contexts with [Browser.NewContext] method. Non-persistent browser contexts don't write any browsing data to disk.
type BrowserContextClearCookiesOptions ¶ added in v0.4400.1
type BrowserContextClearCookiesOptions struct { // Only removes cookies with the given domain. Domain interface{} `json:"domain"` // Only removes cookies with the given name. Name interface{} `json:"name"` // Only removes cookies with the given path. Path interface{} `json:"path"` }
type BrowserContextCloseOptions ¶ added in v0.4001.0
type BrowserContextCloseOptions struct { // The reason to be reported to the operations interrupted by the context closure. Reason *string `json:"reason"` }
type BrowserContextExpectConsoleMessageOptions ¶ added in v0.3500.0
type BrowserContextExpectConsoleMessageOptions struct { // Receives the [ConsoleMessage] object and resolves to truthy value when the waiting should resolve. Predicate func(ConsoleMessage) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type BrowserContextExpectEventOptions ¶ added in v0.3500.0
type BrowserContextExpectEventOptions struct { // Receives the event data and resolves to truthy value when the waiting should resolve. Predicate interface{} `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type BrowserContextExpectPageOptions ¶ added in v0.3500.0
type BrowserContextExpectPageOptions struct { // Receives the [Page] object and resolves to truthy value when the waiting should resolve. Predicate func(Page) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type BrowserContextGrantPermissionsOptions ¶
type BrowserContextGrantPermissionsOptions struct { // The [origin] to grant permissions to, e.g. "https://example.com". Origin *string `json:"origin"` }
type BrowserContextRouteFromHAROptions ¶ added in v0.3500.0
type BrowserContextRouteFromHAROptions struct { // - If set to 'abort' any request not found in the HAR file will be aborted. // - If set to 'fallback' falls through to the next route handler in the handler chain. // Defaults to abort. NotFound *HarNotFound `json:"notFound"` // If specified, updates the given HAR with the actual network information instead of serving from file. The file is // written to disk when [BrowserContext.Close] is called. Update *bool `json:"update"` // Optional setting to control resource content management. If `attach` is specified, resources are persisted as // separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. UpdateContent *RouteFromHarUpdateContentPolicy `json:"updateContent"` // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to // `minimal`. UpdateMode *HarMode `json:"updateMode"` // A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the // pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. URL interface{} `json:"url"` }
type BrowserContextUnrouteAllOptions ¶ added in v0.4101.0
type BrowserContextUnrouteAllOptions struct { // Specifies whether to wait for already running handlers and what to do if they throw errors: // - `default` - do not wait for current handler calls (if any) to finish, if unrouted handler throws, it may // result in unhandled error // - `wait` - wait for current handler calls (if any) to finish // - `ignoreErrors` - do not wait for current handler calls (if any) to finish, all errors thrown by the handlers // after unrouting are silently caught Behavior *UnrouteBehavior `json:"behavior"` }
type BrowserContextWaitForEventOptions ¶ added in v0.3500.0
type BrowserContextWaitForEventOptions struct { // Receives the event data and resolves to truthy value when the waiting should resolve. Predicate interface{} `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type BrowserNewContextOptions ¶
type BrowserNewContextOptions struct { // Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted. AcceptDownloads *bool `json:"acceptDownloads"` // When using [Page.Goto], [Page.Route], [Page.WaitForURL], [Page.ExpectRequest], or [Page.ExpectResponse] it takes // the base URL in consideration by using the [`URL()`] // constructor for building the corresponding URL. Unset by default. Examples: // - baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html` // - baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in // `http://localhost:3000/foo/bar.html` // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in // `http://localhost:3000/bar.html` // // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL BaseURL *string `json:"baseURL"` // Toggles bypassing page's Content-Security-Policy. Defaults to `false`. BypassCSP *bool `json:"bypassCSP"` // TLS Client Authentication allows the server to request a client certificate and verify it. // // # Details // // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided // with an exact match to the request origin that the certificate is valid for. // **NOTE** Using Client Certificates in combination with Proxy Servers is not supported. // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it // work by replacing `localhost` with `local.playwright`. ClientCertificates []ClientCertificate `json:"clientCertificates"` // Emulates `prefers-colors-scheme` media feature, supported values are `light`, `dark`, `no-preference`. See // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to // `light`. ColorScheme *ColorScheme `json:"colorScheme"` // Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about // [emulating devices with device scale factor]. // // [emulating devices with device scale factor]: https://playwright.dev/docs/emulation#devices DeviceScaleFactor *float64 `json:"deviceScaleFactor"` // An object containing additional HTTP headers to be sent with every request. Defaults to none. ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` // Emulates `forced-colors` media feature, supported values are `active`, `none`. See [Page.EmulateMedia] for // more details. Passing `no-override` resets emulation to system defaults. Defaults to `none`. ForcedColors *ForcedColors `json:"forcedColors"` Geolocation *Geolocation `json:"geolocation"` // Specifies if viewport supports touch events. Defaults to false. Learn more about // [mobile emulation]. // // [mobile emulation]: https://playwright.dev/docs/emulation#devices HasTouch *bool `json:"hasTouch"` // Credentials for [HTTP authentication]. If no // origin is specified, the username and password are sent to any servers upon unauthorized responses. // // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication HttpCredentials *HttpCredentials `json:"httpCredentials"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, // so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more // about [mobile emulation]. // // [mobile emulation]: https://playwright.dev/docs/emulation#ismobile IsMobile *bool `json:"isMobile"` // Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about // [disabling JavaScript]. // // [disabling JavaScript]: https://playwright.dev/docs/emulation#javascript-enabled JavaScriptEnabled *bool `json:"javaScriptEnabled"` // Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, // `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default // locale. Learn more about emulation in our [emulation guide]. // // [emulation guide]: https://playwright.dev/docs/emulation#locale--timezone Locale *string `json:"locale"` // Does not enforce fixed viewport, allows resizing window in the headed mode. NoViewport *bool `json:"noViewport"` // Whether to emulate network being offline. Defaults to `false`. Learn more about // [network emulation]. // // [network emulation]: https://playwright.dev/docs/emulation#offline Offline *bool `json:"offline"` // A list of permissions to grant to all pages in this context. See [BrowserContext.GrantPermissions] for more // details. Defaults to none. Permissions []string `json:"permissions"` // Network proxy settings to use with this context. Defaults to none. Proxy *Proxy `json:"proxy"` // Optional setting to control resource content management. If `omit` is specified, content is not persisted. If // `attach` is specified, resources are persisted as separate files and all of these files are archived along with the // HAR file. Defaults to `embed`, which stores content inline the HAR file as per HAR specification. RecordHarContent *HarContentPolicy `json:"recordHarContent"` // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. RecordHarMode *HarMode `json:"recordHarMode"` // Optional setting to control whether to omit request content from the HAR. Defaults to `false`. RecordHarOmitContent *bool `json:"recordHarOmitContent"` // Enables [HAR] recording for all pages into the specified HAR file // on the filesystem. If not specified, the HAR is not recorded. Make sure to call [BrowserContext.Close] for the HAR // to be saved. // // [HAR]: http://www.softwareishard.com/blog/har-12-spec RecordHarPath *string `json:"recordHarPath"` RecordHarURLFilter interface{} `json:"recordHarUrlFilter"` // Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. // Make sure to await [BrowserContext.Close] for videos to be saved. RecordVideo *RecordVideo `json:"recordVideo"` // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. See // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to // `no-preference`. ReducedMotion *ReducedMotion `json:"reducedMotion"` // Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the // “viewport” is set. Screen *Size `json:"screen"` // Whether to allow sites to register Service workers. Defaults to `allow`. // - `allow`: [Service Workers] can be // registered. // - `block`: Playwright will block all registration of Service Workers. // // [Service Workers]: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API ServiceWorkers *ServiceWorkerPolicy `json:"serviceWorkers"` // Learn more about [storage state and auth]. // Populates context with given storage state. This option can be used to initialize context with logged-in // information obtained via [BrowserContext.StorageState]. // // [storage state and auth]: https://playwright.dev/docs/auth StorageState *OptionalStorageState `json:"storageState"` // Populates context with given storage state. This option can be used to initialize context with logged-in // information obtained via [BrowserContext.StorageState]. Path to the file with saved storage state. StorageStatePath *string `json:"storageStatePath"` // If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on // selectors that imply single target DOM element will throw when more than one element matches the selector. This // option does not affect any Locator APIs (Locators are always strict). Defaults to `false`. See [Locator] to learn // more about the strict mode. StrictSelectors *bool `json:"strictSelectors"` // Changes the timezone of the context. See // [ICU's metaZones.txt] // for a list of supported timezone IDs. Defaults to the system timezone. // // [ICU's metaZones.txt]: https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1 TimezoneId *string `json:"timezoneId"` // Specific user agent to use in this context. UserAgent *string `json:"userAgent"` // Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed // viewport. Learn more about [viewport emulation]. // // [viewport emulation]: https://playwright.dev/docs/emulation#viewport Viewport *Size `json:"viewport"` }
type BrowserNewPageOptions ¶
type BrowserNewPageOptions struct { // Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted. AcceptDownloads *bool `json:"acceptDownloads"` // When using [Page.Goto], [Page.Route], [Page.WaitForURL], [Page.ExpectRequest], or [Page.ExpectResponse] it takes // the base URL in consideration by using the [`URL()`] // constructor for building the corresponding URL. Unset by default. Examples: // - baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html` // - baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in // `http://localhost:3000/foo/bar.html` // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in // `http://localhost:3000/bar.html` // // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL BaseURL *string `json:"baseURL"` // Toggles bypassing page's Content-Security-Policy. Defaults to `false`. BypassCSP *bool `json:"bypassCSP"` // TLS Client Authentication allows the server to request a client certificate and verify it. // // # Details // // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided // with an exact match to the request origin that the certificate is valid for. // **NOTE** Using Client Certificates in combination with Proxy Servers is not supported. // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it // work by replacing `localhost` with `local.playwright`. ClientCertificates []ClientCertificate `json:"clientCertificates"` // Emulates `prefers-colors-scheme` media feature, supported values are `light`, `dark`, `no-preference`. See // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to // `light`. ColorScheme *ColorScheme `json:"colorScheme"` // Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about // [emulating devices with device scale factor]. // // [emulating devices with device scale factor]: https://playwright.dev/docs/emulation#devices DeviceScaleFactor *float64 `json:"deviceScaleFactor"` // An object containing additional HTTP headers to be sent with every request. Defaults to none. ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` // Emulates `forced-colors` media feature, supported values are `active`, `none`. See [Page.EmulateMedia] for // more details. Passing `no-override` resets emulation to system defaults. Defaults to `none`. ForcedColors *ForcedColors `json:"forcedColors"` Geolocation *Geolocation `json:"geolocation"` // Specifies if viewport supports touch events. Defaults to false. Learn more about // [mobile emulation]. // // [mobile emulation]: https://playwright.dev/docs/emulation#devices HasTouch *bool `json:"hasTouch"` // Credentials for [HTTP authentication]. If no // origin is specified, the username and password are sent to any servers upon unauthorized responses. // // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication HttpCredentials *HttpCredentials `json:"httpCredentials"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, // so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more // about [mobile emulation]. // // [mobile emulation]: https://playwright.dev/docs/emulation#ismobile IsMobile *bool `json:"isMobile"` // Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about // [disabling JavaScript]. // // [disabling JavaScript]: https://playwright.dev/docs/emulation#javascript-enabled JavaScriptEnabled *bool `json:"javaScriptEnabled"` // Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, // `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default // locale. Learn more about emulation in our [emulation guide]. // // [emulation guide]: https://playwright.dev/docs/emulation#locale--timezone Locale *string `json:"locale"` // Does not enforce fixed viewport, allows resizing window in the headed mode. NoViewport *bool `json:"noViewport"` // Whether to emulate network being offline. Defaults to `false`. Learn more about // [network emulation]. // // [network emulation]: https://playwright.dev/docs/emulation#offline Offline *bool `json:"offline"` // A list of permissions to grant to all pages in this context. See [BrowserContext.GrantPermissions] for more // details. Defaults to none. Permissions []string `json:"permissions"` // Network proxy settings to use with this context. Defaults to none. Proxy *Proxy `json:"proxy"` // Optional setting to control resource content management. If `omit` is specified, content is not persisted. If // `attach` is specified, resources are persisted as separate files and all of these files are archived along with the // HAR file. Defaults to `embed`, which stores content inline the HAR file as per HAR specification. RecordHarContent *HarContentPolicy `json:"recordHarContent"` // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. RecordHarMode *HarMode `json:"recordHarMode"` // Optional setting to control whether to omit request content from the HAR. Defaults to `false`. RecordHarOmitContent *bool `json:"recordHarOmitContent"` // Enables [HAR] recording for all pages into the specified HAR file // on the filesystem. If not specified, the HAR is not recorded. Make sure to call [BrowserContext.Close] for the HAR // to be saved. // // [HAR]: http://www.softwareishard.com/blog/har-12-spec RecordHarPath *string `json:"recordHarPath"` RecordHarURLFilter interface{} `json:"recordHarUrlFilter"` // Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. // Make sure to await [BrowserContext.Close] for videos to be saved. RecordVideo *RecordVideo `json:"recordVideo"` // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. See // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to // `no-preference`. ReducedMotion *ReducedMotion `json:"reducedMotion"` // Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the // “viewport” is set. Screen *Size `json:"screen"` // Whether to allow sites to register Service workers. Defaults to `allow`. // - `allow`: [Service Workers] can be // registered. // - `block`: Playwright will block all registration of Service Workers. // // [Service Workers]: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API ServiceWorkers *ServiceWorkerPolicy `json:"serviceWorkers"` // Learn more about [storage state and auth]. // Populates context with given storage state. This option can be used to initialize context with logged-in // information obtained via [BrowserContext.StorageState]. // // [storage state and auth]: https://playwright.dev/docs/auth StorageState *OptionalStorageState `json:"storageState"` // Populates context with given storage state. This option can be used to initialize context with logged-in // information obtained via [BrowserContext.StorageState]. Path to the file with saved storage state. StorageStatePath *string `json:"storageStatePath"` // If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on // selectors that imply single target DOM element will throw when more than one element matches the selector. This // option does not affect any Locator APIs (Locators are always strict). Defaults to `false`. See [Locator] to learn // more about the strict mode. StrictSelectors *bool `json:"strictSelectors"` // Changes the timezone of the context. See // [ICU's metaZones.txt] // for a list of supported timezone IDs. Defaults to the system timezone. // // [ICU's metaZones.txt]: https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1 TimezoneId *string `json:"timezoneId"` // Specific user agent to use in this context. UserAgent *string `json:"userAgent"` // Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed // viewport. Learn more about [viewport emulation]. // // [viewport emulation]: https://playwright.dev/docs/emulation#viewport Viewport *Size `json:"viewport"` }
type BrowserStartTracingOptions ¶ added in v0.3500.0
type BrowserStartTracingOptions struct { // specify custom categories to use instead of default. Categories []string `json:"categories"` // Optional, if specified, tracing includes screenshots of the given page. Page Page `json:"page"` // A path to write the trace file to. Path *string `json:"path"` // captures screenshots in the trace. Screenshots *bool `json:"screenshots"` }
type BrowserType ¶
type BrowserType interface { // This method attaches Playwright to an existing browser instance. When connecting to another browser launched via // `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is // compatible with 1.2.x). // // wsEndpoint: A browser websocket endpoint to connect to. Connect(wsEndpoint string, options ...BrowserTypeConnectOptions) (Browser, error) // This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol. // The default browser context is accessible via [Browser.Contexts]. // **NOTE** Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers. // // endpointURL: A CDP websocket endpoint or http url to connect to. For example `http://localhost:9222/` or // `ws://127.0.0.1:9222/devtools/browser/387adf4c-243f-4051-a181-46798f4a46f4`. ConnectOverCDP(endpointURL string, options ...BrowserTypeConnectOverCDPOptions) (Browser, error) // A path where Playwright expects to find a bundled browser executable. ExecutablePath() string // Returns the browser instance. // // [Chrome Canary]: https://www.google.com/chrome/browser/canary.html // [Dev Channel]: https://www.chromium.org/getting-involved/dev-channel // [this article]: https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/ // [This article]: https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md Launch(options ...BrowserTypeLaunchOptions) (Browser, error) // Returns the persistent browser context instance. // Launches browser that uses persistent storage located at “userDataDir” and returns the only context. Closing this // context will automatically close the browser. // // userDataDir: Path to a User Data Directory, which stores browser session data like cookies and local storage. More details for // [Chromium](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md#introduction) and // [Firefox](https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile). Note that Chromium's // user data directory is the **parent** directory of the "Profile Path" seen at `chrome://version`. Pass an empty // string to use a temporary directory instead. LaunchPersistentContext(userDataDir string, options ...BrowserTypeLaunchPersistentContextOptions) (BrowserContext, error) // Returns browser name. For example: `chromium`, `webkit` or `firefox`. Name() string }
BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a typical example of using Playwright to drive automation:
type BrowserTypeConnectOptions ¶
type BrowserTypeConnectOptions struct { // This option exposes network available on the connecting client to the browser being connected to. Consists of a // list of rules separated by comma. // Available rules: // 1. Hostname pattern, for example: `example.com`, `*.org:99`, `x.*.y.com`, `*foo.org`. // 2. IP literal, for example: `127.0.0.1`, `0.0.0.0:99`, `[::1]`, `[0:0::1]:99`. // 3. `<loopback>` that matches local loopback interfaces: `localhost`, `*.localhost`, `127.0.0.1`, `[::1]`. // Some common examples: // 4. `"*"` to expose all network. // 5. `"<loopback>"` to expose localhost network. // 6. `"*.test.internal-domain,*.staging.internal-domain,<loopback>"` to expose test/staging deployments and // localhost. ExposeNetwork *string `json:"exposeNetwork"` // Additional HTTP headers to be sent with web socket connect request. Optional. Headers map[string]string `json:"headers"` // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going // on. Defaults to 0. SlowMo *float64 `json:"slowMo"` // Maximum time in milliseconds to wait for the connection to be established. Defaults to `0` (no timeout). Timeout *float64 `json:"timeout"` }
type BrowserTypeConnectOverCDPOptions ¶
type BrowserTypeConnectOverCDPOptions struct { // Additional HTTP headers to be sent with connect request. Optional. Headers map[string]string `json:"headers"` // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going // on. Defaults to 0. SlowMo *float64 `json:"slowMo"` // Maximum time in milliseconds to wait for the connection to be established. Defaults to `30000` (30 seconds). Pass // `0` to disable timeout. Timeout *float64 `json:"timeout"` }
type BrowserTypeLaunchOptions ¶
type BrowserTypeLaunchOptions struct { // **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality. // Additional arguments to pass to the browser instance. The list of Chromium flags can be found // [here]. // // [here]: https://peter.sh/experiments/chromium-command-line-switches/ Args []string `json:"args"` // Browser distribution channel. Supported values are "chrome", "chrome-beta", "chrome-dev", "chrome-canary", // "msedge", "msedge-beta", "msedge-dev", "msedge-canary". Read more about using // [Google Chrome and Microsoft Edge]. // // [Google Chrome and Microsoft Edge]: https://playwright.dev/docs/browsers#google-chrome--microsoft-edge Channel *string `json:"channel"` // Enable Chromium sandboxing. Defaults to `false`. ChromiumSandbox *bool `json:"chromiumSandbox"` // **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the // “headless” option will be set `false`. // // Deprecated: Use [debugging tools] instead. // // [debugging tools]: https://playwright.dev/docs/debug Devtools *bool `json:"devtools"` // If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and // is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were // created in is closed. DownloadsPath *string `json:"downloadsPath"` // Specify environment variables that will be visible to the browser. Defaults to `process.env`. Env map[string]string `json:"env"` // Path to a browser executable to run instead of the bundled one. If “executablePath” is a relative path, then it is // resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, // Firefox or WebKit, use at your own risk. ExecutablePath *string `json:"executablePath"` // Firefox user preferences. Learn more about the Firefox user preferences at // [`about:config`]. // // [`about:config`]: https://support.mozilla.org/en-US/kb/about-config-editor-firefox FirefoxUserPrefs map[string]interface{} `json:"firefoxUserPrefs"` // Close the browser process on SIGHUP. Defaults to `true`. HandleSIGHUP *bool `json:"handleSIGHUP"` // Close the browser process on Ctrl-C. Defaults to `true`. HandleSIGINT *bool `json:"handleSIGINT"` // Close the browser process on SIGTERM. Defaults to `true`. HandleSIGTERM *bool `json:"handleSIGTERM"` // Whether to run browser in headless mode. More details for // [Chromium] and // [Firefox]. Defaults to `true` unless the // “devtools” option is `true`. // // [Chromium]: https://developers.google.com/web/updates/2017/04/headless-chrome // [Firefox]: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode Headless *bool `json:"headless"` // If `true`, Playwright does not pass its own configurations args and only uses the ones from “args”. Dangerous // option; use with care. Defaults to `false`. IgnoreAllDefaultArgs *bool `json:"ignoreAllDefaultArgs"` // If `true`, Playwright does not pass its own configurations args and only uses the ones from “args”. Dangerous // option; use with care. IgnoreDefaultArgs []string `json:"ignoreDefaultArgs"` // Network proxy settings. Proxy *Proxy `json:"proxy"` // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going // on. SlowMo *float64 `json:"slowMo"` // Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` // to disable timeout. Timeout *float64 `json:"timeout"` // If specified, traces are saved into this directory. TracesDir *string `json:"tracesDir"` }
type BrowserTypeLaunchPersistentContextOptions ¶
type BrowserTypeLaunchPersistentContextOptions struct { // Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted. AcceptDownloads *bool `json:"acceptDownloads"` // **NOTE** Use custom browser args at your own risk, as some of them may break Playwright functionality. // Additional arguments to pass to the browser instance. The list of Chromium flags can be found // [here]. // // [here]: https://peter.sh/experiments/chromium-command-line-switches/ Args []string `json:"args"` // When using [Page.Goto], [Page.Route], [Page.WaitForURL], [Page.ExpectRequest], or [Page.ExpectResponse] it takes // the base URL in consideration by using the [`URL()`] // constructor for building the corresponding URL. Unset by default. Examples: // - baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html` // - baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in // `http://localhost:3000/foo/bar.html` // - baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in // `http://localhost:3000/bar.html` // // [`URL()`]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL BaseURL *string `json:"baseURL"` // Toggles bypassing page's Content-Security-Policy. Defaults to `false`. BypassCSP *bool `json:"bypassCSP"` // Browser distribution channel. Supported values are "chrome", "chrome-beta", "chrome-dev", "chrome-canary", // "msedge", "msedge-beta", "msedge-dev", "msedge-canary". Read more about using // [Google Chrome and Microsoft Edge]. // // [Google Chrome and Microsoft Edge]: https://playwright.dev/docs/browsers#google-chrome--microsoft-edge Channel *string `json:"channel"` // Enable Chromium sandboxing. Defaults to `false`. ChromiumSandbox *bool `json:"chromiumSandbox"` // TLS Client Authentication allows the server to request a client certificate and verify it. // // # Details // // An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, // a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, // `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided // with an exact match to the request origin that the certificate is valid for. // **NOTE** Using Client Certificates in combination with Proxy Servers is not supported. // **NOTE** When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it // work by replacing `localhost` with `local.playwright`. ClientCertificates []ClientCertificate `json:"clientCertificates"` // Emulates `prefers-colors-scheme` media feature, supported values are `light`, `dark`, `no-preference`. See // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to // `light`. ColorScheme *ColorScheme `json:"colorScheme"` // Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about // [emulating devices with device scale factor]. // // [emulating devices with device scale factor]: https://playwright.dev/docs/emulation#devices DeviceScaleFactor *float64 `json:"deviceScaleFactor"` // **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the // “headless” option will be set `false`. // // Deprecated: Use [debugging tools] instead. // // [debugging tools]: https://playwright.dev/docs/debug Devtools *bool `json:"devtools"` // If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and // is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were // created in is closed. DownloadsPath *string `json:"downloadsPath"` // Specify environment variables that will be visible to the browser. Defaults to `process.env`. Env map[string]string `json:"env"` // Path to a browser executable to run instead of the bundled one. If “executablePath” is a relative path, then it is // resolved relative to the current working directory. Note that Playwright only works with the bundled Chromium, // Firefox or WebKit, use at your own risk. ExecutablePath *string `json:"executablePath"` // An object containing additional HTTP headers to be sent with every request. Defaults to none. ExtraHttpHeaders map[string]string `json:"extraHTTPHeaders"` // Firefox user preferences. Learn more about the Firefox user preferences at // [`about:config`]. // // [`about:config`]: https://support.mozilla.org/en-US/kb/about-config-editor-firefox FirefoxUserPrefs map[string]interface{} `json:"firefoxUserPrefs"` // Emulates `forced-colors` media feature, supported values are `active`, `none`. See [Page.EmulateMedia] for // more details. Passing `no-override` resets emulation to system defaults. Defaults to `none`. ForcedColors *ForcedColors `json:"forcedColors"` Geolocation *Geolocation `json:"geolocation"` // Close the browser process on SIGHUP. Defaults to `true`. HandleSIGHUP *bool `json:"handleSIGHUP"` // Close the browser process on Ctrl-C. Defaults to `true`. HandleSIGINT *bool `json:"handleSIGINT"` // Close the browser process on SIGTERM. Defaults to `true`. HandleSIGTERM *bool `json:"handleSIGTERM"` // Specifies if viewport supports touch events. Defaults to false. Learn more about // [mobile emulation]. // // [mobile emulation]: https://playwright.dev/docs/emulation#devices HasTouch *bool `json:"hasTouch"` // Whether to run browser in headless mode. More details for // [Chromium] and // [Firefox]. Defaults to `true` unless the // “devtools” option is `true`. // // [Chromium]: https://developers.google.com/web/updates/2017/04/headless-chrome // [Firefox]: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode Headless *bool `json:"headless"` // Credentials for [HTTP authentication]. If no // origin is specified, the username and password are sent to any servers upon unauthorized responses. // // [HTTP authentication]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication HttpCredentials *HttpCredentials `json:"httpCredentials"` // If `true`, Playwright does not pass its own configurations args and only uses the ones from “args”. Dangerous // option; use with care. Defaults to `false`. IgnoreAllDefaultArgs *bool `json:"ignoreAllDefaultArgs"` // If `true`, Playwright does not pass its own configurations args and only uses the ones from “args”. Dangerous // option; use with care. IgnoreDefaultArgs []string `json:"ignoreDefaultArgs"` // Whether to ignore HTTPS errors when sending network requests. Defaults to `false`. IgnoreHttpsErrors *bool `json:"ignoreHTTPSErrors"` // Whether the `meta viewport` tag is taken into account and touch events are enabled. isMobile is a part of device, // so you don't actually need to set it manually. Defaults to `false` and is not supported in Firefox. Learn more // about [mobile emulation]. // // [mobile emulation]: https://playwright.dev/docs/emulation#ismobile IsMobile *bool `json:"isMobile"` // Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about // [disabling JavaScript]. // // [disabling JavaScript]: https://playwright.dev/docs/emulation#javascript-enabled JavaScriptEnabled *bool `json:"javaScriptEnabled"` // Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, // `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default // locale. Learn more about emulation in our [emulation guide]. // // [emulation guide]: https://playwright.dev/docs/emulation#locale--timezone Locale *string `json:"locale"` // Does not enforce fixed viewport, allows resizing window in the headed mode. NoViewport *bool `json:"noViewport"` // Whether to emulate network being offline. Defaults to `false`. Learn more about // [network emulation]. // // [network emulation]: https://playwright.dev/docs/emulation#offline Offline *bool `json:"offline"` // A list of permissions to grant to all pages in this context. See [BrowserContext.GrantPermissions] for more // details. Defaults to none. Permissions []string `json:"permissions"` // Network proxy settings. Proxy *Proxy `json:"proxy"` // Optional setting to control resource content management. If `omit` is specified, content is not persisted. If // `attach` is specified, resources are persisted as separate files and all of these files are archived along with the // HAR file. Defaults to `embed`, which stores content inline the HAR file as per HAR specification. RecordHarContent *HarContentPolicy `json:"recordHarContent"` // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. RecordHarMode *HarMode `json:"recordHarMode"` // Optional setting to control whether to omit request content from the HAR. Defaults to `false`. RecordHarOmitContent *bool `json:"recordHarOmitContent"` // Enables [HAR] recording for all pages into the specified HAR file // on the filesystem. If not specified, the HAR is not recorded. Make sure to call [BrowserContext.Close] for the HAR // to be saved. // // [HAR]: http://www.softwareishard.com/blog/har-12-spec RecordHarPath *string `json:"recordHarPath"` RecordHarURLFilter interface{} `json:"recordHarUrlFilter"` // Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. // Make sure to await [BrowserContext.Close] for videos to be saved. RecordVideo *RecordVideo `json:"recordVideo"` // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. See // [Page.EmulateMedia] for more details. Passing `no-override` resets emulation to system defaults. Defaults to // `no-preference`. ReducedMotion *ReducedMotion `json:"reducedMotion"` // Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the // “viewport” is set. Screen *Size `json:"screen"` // Whether to allow sites to register Service workers. Defaults to `allow`. // - `allow`: [Service Workers] can be // registered. // - `block`: Playwright will block all registration of Service Workers. // // [Service Workers]: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API ServiceWorkers *ServiceWorkerPolicy `json:"serviceWorkers"` // Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going // on. SlowMo *float64 `json:"slowMo"` // If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations on // selectors that imply single target DOM element will throw when more than one element matches the selector. This // option does not affect any Locator APIs (Locators are always strict). Defaults to `false`. See [Locator] to learn // more about the strict mode. StrictSelectors *bool `json:"strictSelectors"` // Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` // to disable timeout. Timeout *float64 `json:"timeout"` // Changes the timezone of the context. See // [ICU's metaZones.txt] // for a list of supported timezone IDs. Defaults to the system timezone. // // [ICU's metaZones.txt]: https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1 TimezoneId *string `json:"timezoneId"` // If specified, traces are saved into this directory. TracesDir *string `json:"tracesDir"` // Specific user agent to use in this context. UserAgent *string `json:"userAgent"` // Sets a consistent viewport for each page. Defaults to an 1280x720 viewport. `no_viewport` disables the fixed // viewport. Learn more about [viewport emulation]. // // [viewport emulation]: https://playwright.dev/docs/emulation#viewport Viewport *Size `json:"viewport"` }
type CDPSession ¶
type CDPSession interface { EventEmitter // Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be // used to send messages. Detach() error // // 1. method: Protocol method name. // 2. params: Optional method parameters. Send(method string, params map[string]interface{}) (interface{}, error) }
The `CDPSession` instances are used to talk raw Chrome Devtools Protocol:
- protocol methods can be called with `session.send` method.
- protocol events can be subscribed to with `session.on` method.
Useful links:
- Documentation on DevTools Protocol can be found here: DevTools Protocol Viewer.
- Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
type ClientCertificate ¶ added in v0.4700.0
type ClientCertificate struct { // Exact origin that the certificate is valid for. Origin includes `https` protocol, a hostname and optionally a port. Origin string `json:"origin"` // Path to the file with the certificate in PEM format. CertPath *string `json:"certPath"` // Direct value of the certificate in PEM format. Cert []byte `json:"cert"` // Path to the file with the private key in PEM format. KeyPath *string `json:"keyPath"` // Direct value of the private key in PEM format. Key []byte `json:"key"` // Path to the PFX or PKCS12 encoded private key and certificate chain. PfxPath *string `json:"pfxPath"` // Direct value of the PFX or PKCS12 encoded private key and certificate chain. Pfx []byte `json:"pfx"` // Passphrase for the private key (PEM or PFX). Passphrase *string `json:"passphrase"` }
type Clock ¶ added in v0.4501.0
type Clock interface { // Advance the clock by jumping forward in time. Only fires due timers at most once. This is equivalent to user // closing the laptop lid for a while and reopening it later, after given time. // // ticks: Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are // "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds. FastForward(ticks interface{}) error // Install fake implementations for the following time-related functions: // - `Date` // - `setTimeout` // - `clearTimeout` // - `setInterval` // - `clearInterval` // - `requestAnimationFrame` // - `cancelAnimationFrame` // - `requestIdleCallback` // - `cancelIdleCallback` // - `performance` // Fake timers are used to manually control the flow of time in tests. They allow you to advance time, fire timers, // and control the behavior of time-dependent functions. See [Clock.RunFor] and [Clock.FastForward] for more // information. Install(options ...ClockInstallOptions) error // Advance the clock, firing all the time-related callbacks. // // ticks: Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are // "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds. RunFor(ticks interface{}) error // Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers are fired // unless [Clock.RunFor], [Clock.FastForward], [Clock.PauseAt] or [Clock.Resume] is called. // Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it // at the specified time and pausing. // // time: Time to pause at. PauseAt(time interface{}) error // Resumes timers. Once this method is called, time resumes flowing, timers are fired as usual. Resume() error // Makes `Date.now` and `new Date()` return fixed fake time at all times, keeps all the timers running. // // time: Time to be set. SetFixedTime(time interface{}) error // Sets current system time but does not trigger any timers. // // time: Time to be set. SetSystemTime(time interface{}) error }
Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn more about clock emulation. Note that clock is installed for the entire BrowserContext, so the time in all the pages and iframes is controlled by the same clock.
type ClockInstallOptions ¶ added in v0.4501.0
type ClockInstallOptions struct {
// Time to initialize with, current system time by default.
Time interface{} `json:"time"`
}
type ColorScheme ¶
type ColorScheme string
type ConsoleMessage ¶
type ConsoleMessage interface { // List of arguments passed to a `console` function call. See also [Page.OnConsole]. Args() []JSHandle Location() *ConsoleMessageLocation // The page that produced this console message, if any. Page() Page // The text of the console message. Text() string // The text of the console message. String() string // One of the following values: `log`, `debug`, `info`, `error`, `warning`, `dir`, `dirxml`, `table`, // `trace`, `clear`, `startGroup`, `startGroupCollapsed`, `endGroup`, `assert`, `profile`, // `profileEnd`, `count`, `timeEnd`. Type() string }
ConsoleMessage objects are dispatched by page via the [Page.OnConsole] event. For each console message logged in the page there will be corresponding event in the Playwright context.
type ConsoleMessageLocation ¶
type Cookie ¶
type Cookie struct { Name string `json:"name"` Value string `json:"value"` Domain string `json:"domain"` Path string `json:"path"` // Unix time in seconds. Expires float64 `json:"expires"` HttpOnly bool `json:"httpOnly"` Secure bool `json:"secure"` SameSite *SameSiteAttribute `json:"sameSite"` }
func (Cookie) ToOptionalCookie ¶ added in v0.4102.0
func (c Cookie) ToOptionalCookie() OptionalCookie
type DeviceDescriptor ¶
type DeviceDescriptor struct { UserAgent string `json:"userAgent"` Viewport *Size `json:"viewport"` Screen *Size `json:"screen"` DeviceScaleFactor float64 `json:"deviceScaleFactor"` IsMobile bool `json:"isMobile"` HasTouch bool `json:"hasTouch"` DefaultBrowserType string `json:"defaultBrowserType"` }
DeviceDescriptor represents a single device
type Dialog ¶
type Dialog interface { // Returns when the dialog has been accepted. Accept(promptText ...string) error // If dialog is prompt, returns default prompt value. Otherwise, returns empty string. DefaultValue() string // Returns when the dialog has been dismissed. Dismiss() error // A message displayed in the dialog. Message() string // The page that initiated this dialog, if available. Page() Page // Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. Type() string }
Dialog objects are dispatched by page via the [Page.OnDialog] event. An example of using `Dialog` class: **NOTE** Dialogs are dismissed automatically, unless there is a [Page.OnDialog] listener. When listener is present, it **must** either [Dialog.Accept] or [Dialog.Dismiss] the dialog - otherwise the page will freeze waiting for the dialog, and actions like click will never finish.
type Download ¶
type Download interface { // Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations, // `download.failure()` would resolve to `canceled`. Cancel() error // Deletes the downloaded file. Will wait for the download to finish if necessary. Delete() error // Returns download error if any. Will wait for the download to finish if necessary. Failure() error // Get the page that the download belongs to. Page() Page // Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method // will wait for the download to finish if necessary. The method throws when connected remotely. // Note that the download's file name is a random GUID, use [Download.SuggestedFilename] to get suggested file name. Path() (string, error) // Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. // Will wait for the download to finish if necessary. // // path: Path where the download should be copied. SaveAs(path string) error // Returns suggested filename for this download. It is typically computed by the browser from the // [`Content-Disposition`] response // header or the `download` attribute. See the spec on [whatwg]. // Different browsers can use different logic for computing it. // // [`Content-Disposition`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition // [whatwg]: https://html.spec.whatwg.org/#downloading-resources SuggestedFilename() string // Returns downloaded url. URL() string String() string }
Download objects are dispatched by page via the [Page.OnDownload] event. All the downloaded files belonging to the browser context are deleted when the browser context is closed. Download event is emitted once the download starts. Download path becomes available once download completes.
type ElementHandle ¶
type ElementHandle interface { JSHandle // This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is // calculated relative to the main frame viewport - which is usually the same as the browser window. // Scrolling affects the returned bounding box, similarly to // [Element.GetBoundingClientRect]. // That means `x` and/or `y` may be negative. // Elements from child frames return the bounding box relative to the main frame, unlike the // [Element.GetBoundingClientRect]. // Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the // following snippet should click the center of the element. // // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect BoundingBox() (*Rect, error) // This method checks the element by performing the following steps: // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already // checked, this method returns immediately. // 2. Wait for [actionability] checks on the element, unless “force” option is set. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to click in the center of the element. // 5. Ensure that the element is now checked. If not, this method throws. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Check] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Check(options ...ElementHandleCheckOptions) error // This method clicks the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Mouse] to click in the center of the element, or the specified “position”. // 4. Wait for initiated navigations to either succeed or fail, unless “noWaitAfter” option is set. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Click] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Click(options ...ElementHandleClickOptions) error // Returns the content frame for element handles referencing iframe nodes, or `null` otherwise ContentFrame() (Frame, error) // This method double clicks the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Mouse] to double click in the center of the element, or the specified “position”. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** `elementHandle.dblclick()` dispatches two `click` events and a single `dblclick` event. // // Deprecated: Use locator-based [Locator.Dblclick] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Dblclick(options ...ElementHandleDblclickOptions) error // The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, // `click` is dispatched. This is equivalent to calling // [element.Click()]. // // Deprecated: Use locator-based [Locator.DispatchEvent] instead. Read more about [locators]. // // 1. typ: DOM event type: `"click"`, `"dragstart"`, etc. // 2. eventInit: Optional event-specific initialization properties. // // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent // [locators]: https://playwright.dev/docs/locators DispatchEvent(typ string, eventInit ...interface{}) error // Returns the return value of “expression”. // The method finds an element matching the specified selector in the `ElementHandle`s subtree and passes it as a // first argument to “expression”. If no elements match the selector, the method throws an error. // If “expression” returns a [Promise], then [ElementHandle.EvalOnSelector] would wait for the promise to resolve and // return its value. // // Deprecated: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests. Use [Locator.Evaluate], other [Locator] helper methods or web-first assertions instead. // // 1. selector: A selector to query for. // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 3. arg: Optional argument to pass to “expression”. EvalOnSelector(selector string, expression string, arg ...interface{}) (interface{}, error) // Returns the return value of “expression”. // The method finds all elements matching the specified selector in the `ElementHandle`'s subtree and passes an array // of matched elements as a first argument to “expression”. // If “expression” returns a [Promise], then [ElementHandle.EvalOnSelectorAll] would wait for the promise to resolve // and return its value. // // Deprecated: In most cases, [Locator.EvaluateAll], other [Locator] helper methods and web-first assertions do a better job. // // 1. selector: A selector to query for. // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 3. arg: Optional argument to pass to “expression”. EvalOnSelectorAll(selector string, expression string, arg ...interface{}) (interface{}, error) // This method waits for [actionability] checks, focuses the element, fills it and triggers an // `input` event after filling. Note that you can pass an empty string to clear the input field. // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an // error. However, if the element is inside the `<label>` element that has an associated // [control], the control will be filled // instead. // To send fine-grained keyboard events, use [Locator.PressSequentially]. // // Deprecated: Use locator-based [Locator.Fill] instead. Read more about [locators]. // // value: Value to set for the `<input>`, `<textarea>` or `[contenteditable]` element. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators Fill(value string, options ...ElementHandleFillOptions) error // Calls [focus] on the element. // // Deprecated: Use locator-based [Locator.Focus] instead. Read more about [locators]. // // [focus]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus // [locators]: https://playwright.dev/docs/locators Focus() error // Returns element attribute value. // // Deprecated: Use locator-based [Locator.GetAttribute] instead. Read more about [locators]. // // name: Attribute name to get the value for. // // [locators]: https://playwright.dev/docs/locators GetAttribute(name string) (string, error) // This method hovers over the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Mouse] to hover over the center of the element, or the specified “position”. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Hover] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Hover(options ...ElementHandleHoverOptions) error // Returns the `element.innerHTML`. // // Deprecated: Use locator-based [Locator.InnerHTML] instead. Read more about [locators]. // // [locators]: https://playwright.dev/docs/locators InnerHTML() (string, error) // Returns the `element.innerText`. // // Deprecated: Use locator-based [Locator.InnerText] instead. Read more about [locators]. // // [locators]: https://playwright.dev/docs/locators InnerText() (string, error) // Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. // Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated // [control], returns the value of the // control. // // Deprecated: Use locator-based [Locator.InputValue] instead. Read more about [locators]. // // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators InputValue(options ...ElementHandleInputValueOptions) (string, error) // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. // // Deprecated: Use locator-based [Locator.IsChecked] instead. Read more about [locators]. // // [locators]: https://playwright.dev/docs/locators IsChecked() (bool, error) // Returns whether the element is disabled, the opposite of [enabled]. // // Deprecated: Use locator-based [Locator.IsDisabled] instead. Read more about [locators]. // // [enabled]: https://playwright.dev/docs/actionability#enabled // [locators]: https://playwright.dev/docs/locators IsDisabled() (bool, error) // Returns whether the element is [editable]. // // Deprecated: Use locator-based [Locator.IsEditable] instead. Read more about [locators]. // // [editable]: https://playwright.dev/docs/actionability#editable // [locators]: https://playwright.dev/docs/locators IsEditable() (bool, error) // Returns whether the element is [enabled]. // // Deprecated: Use locator-based [Locator.IsEnabled] instead. Read more about [locators]. // // [enabled]: https://playwright.dev/docs/actionability#enabled // [locators]: https://playwright.dev/docs/locators IsEnabled() (bool, error) // Returns whether the element is hidden, the opposite of [visible]. // // Deprecated: Use locator-based [Locator.IsHidden] instead. Read more about [locators]. // // [visible]: https://playwright.dev/docs/actionability#visible // [locators]: https://playwright.dev/docs/locators IsHidden() (bool, error) // Returns whether the element is [visible]. // // Deprecated: Use locator-based [Locator.IsVisible] instead. Read more about [locators]. // // [visible]: https://playwright.dev/docs/actionability#visible // [locators]: https://playwright.dev/docs/locators IsVisible() (bool, error) // Returns the frame containing the given element. OwnerFrame() (Frame, error) // Focuses the element, and then uses [Keyboard.Down] and [Keyboard.Up]. // “key” can specify the intended // [keyboardEvent.Key] value or a single character // to generate the text for. A superset of the “key” values can be found // [here]. Examples of the keys are: // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, // etc. // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, // `ControlOrMeta`. // Holding down `Shift` will type the text that corresponds to the “key” in the upper case. // If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective // texts. // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. // // Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators]. // // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. // // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values // [locators]: https://playwright.dev/docs/locators Press(key string, options ...ElementHandlePressOptions) error // The method finds an element matching the specified selector in the `ElementHandle`'s subtree. If no elements match // the selector, returns `null`. // // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators QuerySelector(selector string) (ElementHandle, error) // The method finds all elements matching the specified selector in the `ElementHandle`s subtree. If no elements match // the selector, returns empty array. // // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators QuerySelectorAll(selector string) ([]ElementHandle, error) // This method captures a screenshot of the page, clipped to the size and position of this particular element. If the // element is covered by other elements, it will not be actually visible on the screenshot. If the element is a // scrollable container, only the currently scrolled content will be visible on the screenshot. // This method waits for the [actionability] checks, then scrolls element into view before taking // a screenshot. If the element is detached from DOM, the method throws an error. // Returns the buffer with the captured screenshot. // // Deprecated: Use locator-based [Locator.Screenshot] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Screenshot(options ...ElementHandleScreenshotOptions) ([]byte, error) // This method waits for [actionability] checks, then tries to scroll element into view, unless // it is completely visible as defined by // [IntersectionObserver]'s `ratio`. // Throws when `elementHandle` does not point to an element // [connected] to a Document or a ShadowRoot. // See [scrolling] for alternative ways to scroll. // // Deprecated: Use locator-based [Locator.ScrollIntoViewIfNeeded] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [IntersectionObserver]: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API // [connected]: https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected // [scrolling]: https://playwright.dev/docs/input#scrolling // [locators]: https://playwright.dev/docs/locators ScrollIntoViewIfNeeded(options ...ElementHandleScrollIntoViewIfNeededOptions) error // This method waits for [actionability] checks, waits until all specified options are present in // the `<select>` element and selects these options. // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside // the `<label>` element that has an associated // [control], the control will be used // instead. // Returns the array of option values that have been successfully selected. // Triggers a `change` and `input` event once all the provided options have been selected. // // Deprecated: Use locator-based [Locator.SelectOption] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators SelectOption(values SelectOptionValues, options ...ElementHandleSelectOptionOptions) ([]string, error) // This method waits for [actionability] checks, then focuses the element and selects all its // text content. // If the element is inside the `<label>` element that has an associated // [control], focuses and selects text in // the control instead. // // Deprecated: Use locator-based [Locator.SelectText] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators SelectText(options ...ElementHandleSelectTextOptions) error // This method checks or unchecks an element by performing the following steps: // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. // 2. If the element already has the right checked state, this method returns immediately. // 3. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 4. Scroll the element into view if needed. // 5. Use [Page.Mouse] to click in the center of the element. // 6. Ensure that the element is now checked or unchecked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.SetChecked] instead. Read more about [locators]. // // checked: Whether to check or uncheck the checkbox. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators SetChecked(checked bool, options ...ElementHandleSetCheckedOptions) error // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then // they are resolved relative to the current working directory. For empty array, clears the selected files. For inputs // with a `[webkitdirectory]` attribute, only a single directory path is supported. // This method expects [ElementHandle] to point to an // [input element]. However, if the element is inside // the `<label>` element that has an associated // [control], targets the control instead. // // Deprecated: Use locator-based [Locator.SetInputFiles] instead. Read more about [locators]. // // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators SetInputFiles(files interface{}, options ...ElementHandleSetInputFilesOptions) error // This method taps the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Touchscreen] to tap the center of the element, or the specified “position”. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** `elementHandle.tap()` requires that the `hasTouch` option of the browser context be set to true. // // Deprecated: Use locator-based [Locator.Tap] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Tap(options ...ElementHandleTapOptions) error // Returns the `node.textContent`. // // Deprecated: Use locator-based [Locator.TextContent] instead. Read more about [locators]. // // [locators]: https://playwright.dev/docs/locators TextContent() (string, error) // Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the // text. // To press a special key, like `Control` or `ArrowDown`, use [ElementHandle.Press]. // // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. // // text: A text to type into a focused element. Type(text string, options ...ElementHandleTypeOptions) error // This method checks the element by performing the following steps: // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already // unchecked, this method returns immediately. // 2. Wait for [actionability] checks on the element, unless “force” option is set. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to click in the center of the element. // 5. Ensure that the element is now unchecked. If not, this method throws. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Uncheck] instead. Read more about [locators]. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Uncheck(options ...ElementHandleUncheckOptions) error // Returns when the element satisfies the “state”. // Depending on the “state” parameter, this method waits for one of the [actionability] checks to // pass. This method throws when the element is detached while waiting, unless waiting for the `"hidden"` state. // - `"visible"` Wait until the element is [visible]. // - `"hidden"` Wait until the element is [not visible] or not attached. Note that // waiting for hidden does not throw when the element detaches. // - `"stable"` Wait until the element is both [visible] and // [stable]. // - `"enabled"` Wait until the element is [enabled]. // - `"disabled"` Wait until the element is [not enabled]. // - `"editable"` Wait until the element is [editable]. // If the element does not satisfy the condition for the “timeout” milliseconds, this method will throw. // // state: A state to wait for, see below for more details. // // [actionability]: https://playwright.dev/docs/actionability // [visible]: https://playwright.dev/docs/actionability#visible // [not visible]: https://playwright.dev/docs/actionability#visible // [visible]: https://playwright.dev/docs/actionability#visible // [stable]: https://playwright.dev/docs/actionability#stable // [enabled]: https://playwright.dev/docs/actionability#enabled // [not enabled]: https://playwright.dev/docs/actionability#enabled // [editable]: https://playwright.dev/docs/actionability#editable WaitForElementState(state ElementState, options ...ElementHandleWaitForElementStateOptions) error // Returns element specified by selector when it satisfies “state” option. Returns `null` if waiting for `hidden` or // `detached`. // Wait for the “selector” relative to the element handle to satisfy “state” option (either appear/disappear from dom, // or become visible/hidden). If at the moment of calling the method “selector” already satisfies the condition, the // method will return immediately. If the selector doesn't satisfy the condition for the “timeout” milliseconds, the // function will throw. // // Deprecated: Use web assertions that assert visibility or a locator-based [Locator.WaitFor] instead. // // selector: A selector to query for. WaitForSelector(selector string, options ...ElementHandleWaitForSelectorOptions) (ElementHandle, error) }
ElementHandle represents an in-page DOM element. ElementHandles can be created with the [Page.QuerySelector]
method. **NOTE** The use of ElementHandle is discouraged, use Locator objects and web-first assertions instead. ElementHandle prevents DOM element from garbage collection unless the handle is disposed with [JSHandle.Dispose]. ElementHandles are auto-disposed when their origin frame gets navigated. ElementHandle instances can be used as an argument in [Page.EvalOnSelector] and [Page.Evaluate] methods. The difference between the Locator and ElementHandle is that the ElementHandle points to a particular element, while Locator captures the logic of how to retrieve an element. In the example below, handle points to a particular DOM element on page. If that element changes text or is used by React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to unexpected behaviors. With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So in the snippet below, underlying DOM element is going to be located twice.
type ElementHandleCheckOptions ¶
type ElementHandleCheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type ElementHandleClickOptions ¶
type ElementHandleClickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // defaults to 1. See [UIEvent.Detail]. ClickCount *int `json:"clickCount"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type ElementHandleDblclickOptions ¶
type ElementHandleDblclickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type ElementHandleFillOptions ¶
type ElementHandleFillOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleHoverOptions ¶
type ElementHandleHoverOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type ElementHandleInputValueOptions ¶
type ElementHandleInputValueOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandlePressOptions ¶
type ElementHandlePressOptions struct { // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleScreenshotOptions ¶
type ElementHandleScreenshotOptions struct { // When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different // treatment depending on their duration: // - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event. // - infinite animations are canceled to initial state, and then played over after the screenshot. // Defaults to `"allow"` that leaves animations untouched. Animations *ScreenshotAnimations `json:"animations"` // When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be // changed. Defaults to `"hide"`. Caret *ScreenshotCaret `json:"caret"` // Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink // box `#FF00FF` (customized by “maskColor”) that completely covers its bounding box. Mask []Locator `json:"mask"` // Specify the color of the overlay box for masked elements, in // [CSS color format]. Default color is pink `#FF00FF`. // // [CSS color format]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value MaskColor *string `json:"maskColor"` // Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. // Defaults to `false`. OmitBackground *bool `json:"omitBackground"` // The file path to save the image to. The screenshot type will be inferred from file extension. If “path” is a // relative path, then it is resolved relative to the current working directory. If no path is provided, the image // won't be saved to the disk. Path *string `json:"path"` // The quality of the image, between 0-100. Not applicable to `png` images. Quality *int `json:"quality"` // When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this // will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so // screenshots of high-dpi devices will be twice as large or even larger. // Defaults to `"device"`. Scale *ScreenshotScale `json:"scale"` // Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make // elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces // the Shadow DOM and applies to the inner frames. Style *string `json:"style"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // Specify screenshot type, defaults to `png`. Type *ScreenshotType `json:"type"` }
type ElementHandleScrollIntoViewIfNeededOptions ¶
type ElementHandleScrollIntoViewIfNeededOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleSelectOptionOptions ¶
type ElementHandleSelectOptionOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleSelectTextOptions ¶
type ElementHandleSelectTextOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleSetCheckedOptions ¶
type ElementHandleSetCheckedOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type ElementHandleSetInputFilesOptions ¶
type ElementHandleSetInputFilesOptions struct { // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleTapOptions ¶
type ElementHandleTapOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type ElementHandleTypeOptions ¶
type ElementHandleTypeOptions struct { // Time to wait between key presses in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleUncheckOptions ¶
type ElementHandleUncheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type ElementHandleWaitForElementStateOptions ¶
type ElementHandleWaitForElementStateOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementHandleWaitForSelectorOptions ¶
type ElementHandleWaitForSelectorOptions struct { // Defaults to `visible`. Can be either: // - `attached` - wait for element to be present in DOM. // - `detached` - wait for element to not be present in DOM. // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element // without any content or with `display:none` has an empty bounding box and is not considered visible. // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or // `visibility:hidden`. This is opposite to the `visible` option. State *WaitForSelectorState `json:"state"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ElementState ¶
type ElementState string
type Error ¶
type Error struct { Name string `json:"name"` Message string `json:"message"` Stack string `json:"stack"` }
Error represents a Playwright error
type EventEmitter ¶
type ExposedFunction ¶
type ExposedFunction = func(args ...interface{}) interface{}
ExposedFunction represents the func signature of an exposed function
type FileChooser ¶
type FileChooser interface { // Returns input element associated with this file chooser. Element() ElementHandle // Returns whether this file chooser accepts multiple files. IsMultiple() bool // Returns page this file chooser belongs to. Page() Page // Sets the value of the file input this chooser is associated with. If some of the `filePaths` are relative paths, // then they are resolved relative to the current working directory. For empty array, clears the selected files. SetFiles(files interface{}, options ...FileChooserSetFilesOptions) error }
FileChooser objects are dispatched by the page in the [Page.OnFileChooser] event.
type FileChooserSetFilesOptions ¶
type FileChooserSetFilesOptions struct { // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type ForcedColors ¶
type ForcedColors string
type Frame ¶
type Frame interface { // Returns the added tag when the script's onload fires or when the script content was injected into frame. // Adds a `<script>` tag into the page with the desired url or content. AddScriptTag(options FrameAddScriptTagOptions) (ElementHandle, error) // Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame. // Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the // content. AddStyleTag(options FrameAddStyleTagOptions) (ElementHandle, error) // This method checks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is // already checked, this method returns immediately. // 3. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 4. Scroll the element into view if needed. // 5. Use [Page.Mouse] to click in the center of the element. // 6. Ensure that the element is now checked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Check] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Check(selector string, options ...FrameCheckOptions) error ChildFrames() []Frame // This method clicks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to click in the center of the element, or the specified “position”. // 5. Wait for initiated navigations to either succeed or fail, unless “noWaitAfter” option is set. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Click] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Click(selector string, options ...FrameClickOptions) error // Gets the full HTML contents of the frame, including the doctype. Content() (string, error) // This method double clicks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to double click in the center of the element, or the specified “position”. if the first // click of the `dblclick()` triggers a navigation event, this method will throw. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** `frame.dblclick()` dispatches two `click` events and a single `dblclick` event. // // Deprecated: Use locator-based [Locator.Dblclick] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Dblclick(selector string, options ...FrameDblclickOptions) error // The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, // `click` is dispatched. This is equivalent to calling // [element.Click()]. // // Deprecated: Use locator-based [Locator.DispatchEvent] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. typ: DOM event type: `"click"`, `"dragstart"`, etc. // 3. eventInit: Optional event-specific initialization properties. // // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent // [locators]: https://playwright.dev/docs/locators DispatchEvent(selector string, typ string, eventInit interface{}, options ...FrameDispatchEventOptions) error // // 1. source: A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will // be used. // 2. target: A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first // will be used. DragAndDrop(source string, target string, options ...FrameDragAndDropOptions) error // Returns the return value of “expression”. // The method finds an element matching the specified selector within the frame and passes it as a first argument to // “expression”. If no elements match the selector, the method throws an error. // If “expression” returns a [Promise], then [Frame.EvalOnSelector] would wait for the promise to resolve and return // its value. // // Deprecated: This method does not wait for the element to pass the actionability checks and therefore can lead to the flaky tests. Use [Locator.Evaluate], other [Locator] helper methods or web-first assertions instead. // // 1. selector: A selector to query for. // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 3. arg: Optional argument to pass to “expression”. EvalOnSelector(selector string, expression string, arg interface{}, options ...FrameEvalOnSelectorOptions) (interface{}, error) // Returns the return value of “expression”. // The method finds all elements matching the specified selector within the frame and passes an array of matched // elements as a first argument to “expression”. // If “expression” returns a [Promise], then [Frame.EvalOnSelectorAll] would wait for the promise to resolve and // return its value. // // Deprecated: In most cases, [Locator.EvaluateAll], other [Locator] helper methods and web-first assertions do a better job. // // 1. selector: A selector to query for. // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 3. arg: Optional argument to pass to “expression”. EvalOnSelectorAll(selector string, expression string, arg ...interface{}) (interface{}, error) // Returns the return value of “expression”. // If the function passed to the [Frame.Evaluate] returns a [Promise], then [Frame.Evaluate] would wait for the // promise to resolve and return its value. // If the function passed to the [Frame.Evaluate] returns a non-[Serializable] value, then [Frame.Evaluate] returns // `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: // `-0`, `NaN`, `Infinity`, `-Infinity`. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. Evaluate(expression string, arg ...interface{}) (interface{}, error) // Returns the return value of “expression” as a [JSHandle]. // The only difference between [Frame.Evaluate] and [Frame.EvaluateHandle] is that [Frame.EvaluateHandle] returns // [JSHandle]. // If the function, passed to the [Frame.EvaluateHandle], returns a [Promise], then [Frame.EvaluateHandle] would wait // for the promise to resolve and return its value. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) // This method waits for an element matching “selector”, waits for [actionability] checks, // focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string // to clear the input field. // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an // error. However, if the element is inside the `<label>` element that has an associated // [control], the control will be filled // instead. // To send fine-grained keyboard events, use [Locator.PressSequentially]. // // Deprecated: Use locator-based [Locator.Fill] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. value: Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators Fill(selector string, value string, options ...FrameFillOptions) error // This method fetches an element with “selector” and focuses it. If there's no element matching “selector”, the // method waits until a matching element appears in the DOM. // // Deprecated: Use locator-based [Locator.Focus] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators Focus(selector string, options ...FrameFocusOptions) error // Returns the `frame` or `iframe` element handle which corresponds to this frame. // This is an inverse of [ElementHandle.ContentFrame]. Note that returned handle actually belongs to the parent frame. // This method throws an error if the frame has been detached before `frameElement()` returns. FrameElement() (ElementHandle, error) // When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements // in that iframe. // // selector: A selector to use when resolving DOM element. FrameLocator(selector string) FrameLocator // Returns element attribute value. // // Deprecated: Use locator-based [Locator.GetAttribute] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. name: Attribute name to get the value for. // // [locators]: https://playwright.dev/docs/locators GetAttribute(selector string, name string, options ...FrameGetAttributeOptions) (string, error) // Allows locating elements by their alt text. // // text: Text to locate the element for. GetByAltText(text interface{}, options ...FrameGetByAltTextOptions) Locator // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the // `aria-label` attribute. // // text: Text to locate the element for. GetByLabel(text interface{}, options ...FrameGetByLabelOptions) Locator // Allows locating input elements by the placeholder text. // // text: Text to locate the element for. GetByPlaceholder(text interface{}, options ...FrameGetByPlaceholderOptions) Locator // Allows locating elements by their [ARIA role], // [ARIA attributes] and // [accessible name]. // // # Details // // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback // about the ARIA guidelines. // Many html elements have an implicitly [defined role] // that is recognized by the role selector. You can find all the // [supported roles here]. ARIA guidelines **do not recommend** // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. // // role: Required aria role. // // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions GetByRole(role AriaRole, options ...FrameGetByRoleOptions) Locator // Locate element by the test id. // // # Details // // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a // different test id attribute if necessary. // // testId: Id to locate the element by. GetByTestId(testId interface{}) Locator // Allows locating elements that contain given text. // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the // text content. // // # Details // // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into // one, turns line breaks into spaces and ignores leading and trailing whitespace. // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. // // text: Text to locate the element for. GetByText(text interface{}, options ...FrameGetByTextOptions) Locator // Allows locating elements by their title attribute. // // text: Text to locate the element for. GetByTitle(text interface{}, options ...FrameGetByTitleOptions) Locator // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of // the last redirect. // The method will throw an error if: // - there's an SSL error (e.g. in case of self-signed certificates). // - target URL is invalid. // - the “timeout” is exceeded during navigation. // - the remote server does not respond or is unreachable. // - the main resource failed to load. // The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 // "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling // [Response.Status]. // **NOTE** The method either throws an error or returns a main resource response. The only exceptions are navigation // to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`. // **NOTE** Headless mode doesn't support navigation to a PDF document. See the // [upstream issue]. // // url: URL to navigate frame to. The url should include scheme, e.g. `https://`. // // [upstream issue]: https://bugs.chromium.org/p/chromium/issues/detail?id=761295 Goto(url string, options ...FrameGotoOptions) (Response, error) // This method hovers over an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to hover over the center of the element, or the specified “position”. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Hover] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Hover(selector string, options ...FrameHoverOptions) error // Returns `element.innerHTML`. // // Deprecated: Use locator-based [Locator.InnerHTML] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators InnerHTML(selector string, options ...FrameInnerHTMLOptions) (string, error) // Returns `element.innerText`. // // Deprecated: Use locator-based [Locator.InnerText] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators InnerText(selector string, options ...FrameInnerTextOptions) (string, error) // Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. // Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated // [control], returns the value of the // control. // // Deprecated: Use locator-based [Locator.InputValue] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators InputValue(selector string, options ...FrameInputValueOptions) (string, error) // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. // // Deprecated: Use locator-based [Locator.IsChecked] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators IsChecked(selector string, options ...FrameIsCheckedOptions) (bool, error) // Returns `true` if the frame has been detached, or `false` otherwise. IsDetached() bool // Returns whether the element is disabled, the opposite of [enabled]. // // Deprecated: Use locator-based [Locator.IsDisabled] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [enabled]: https://playwright.dev/docs/actionability#enabled // [locators]: https://playwright.dev/docs/locators IsDisabled(selector string, options ...FrameIsDisabledOptions) (bool, error) // Returns whether the element is [editable]. // // Deprecated: Use locator-based [Locator.IsEditable] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [editable]: https://playwright.dev/docs/actionability#editable // [locators]: https://playwright.dev/docs/locators IsEditable(selector string, options ...FrameIsEditableOptions) (bool, error) // Returns whether the element is [enabled]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [enabled]: https://playwright.dev/docs/actionability#enabled IsEnabled(selector string, options ...FrameIsEnabledOptions) (bool, error) // Returns whether the element is hidden, the opposite of [visible]. “selector” that // does not match any elements is considered hidden. // // Deprecated: Use locator-based [Locator.IsHidden] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [visible]: https://playwright.dev/docs/actionability#visible // [locators]: https://playwright.dev/docs/locators IsHidden(selector string, options ...FrameIsHiddenOptions) (bool, error) // Returns whether the element is [visible]. “selector” that does not match any elements // is considered not visible. // // Deprecated: Use locator-based [Locator.IsVisible] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [visible]: https://playwright.dev/docs/actionability#visible // [locators]: https://playwright.dev/docs/locators IsVisible(selector string, options ...FrameIsVisibleOptions) (bool, error) // The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved // to the element immediately before performing an action, so a series of actions on the same locator can in fact be // performed on different DOM elements. That would happen if the DOM structure between those actions has changed. // [Learn more about locators]. // [Learn more about locators]. // // selector: A selector to use when resolving DOM element. // // [Learn more about locators]: https://playwright.dev/docs/locators // [Learn more about locators]: https://playwright.dev/docs/locators Locator(selector string, options ...FrameLocatorOptions) Locator // Returns frame's name attribute as specified in the tag. // If the name is empty, returns the id attribute instead. // **NOTE** This value is calculated once when the frame is created, and will not update if the attribute is changed // later. Name() string // Returns the page containing this frame. Page() Page // Parent frame, if any. Detached frames and main frames return `null`. ParentFrame() Frame // “key” can specify the intended // [keyboardEvent.Key] value or a single character // to generate the text for. A superset of the “key” values can be found // [here]. Examples of the keys are: // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, // etc. // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. // Holding down `Shift` will type the text that corresponds to the “key” in the upper case. // If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective // texts. // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. // // Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. // // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values // [locators]: https://playwright.dev/docs/locators Press(selector string, key string, options ...FramePressOptions) error // Returns the ElementHandle pointing to the frame element. // **NOTE** The use of [ElementHandle] is discouraged, use [Locator] objects and web-first assertions instead. // The method finds an element matching the specified selector within the frame. If no elements match the selector, // returns `null`. // // Deprecated: Use locator-based [Frame.Locator] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators QuerySelector(selector string, options ...FrameQuerySelectorOptions) (ElementHandle, error) // Returns the ElementHandles pointing to the frame elements. // **NOTE** The use of [ElementHandle] is discouraged, use [Locator] objects instead. // The method finds all elements matching the specified selector within the frame. If no elements match the selector, // returns empty array. // // Deprecated: Use locator-based [Frame.Locator] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators QuerySelectorAll(selector string) ([]ElementHandle, error) // This method waits for an element matching “selector”, waits for [actionability] checks, waits // until all specified options are present in the `<select>` element and selects these options. // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside // the `<label>` element that has an associated // [control], the control will be used // instead. // Returns the array of option values that have been successfully selected. // Triggers a `change` and `input` event once all the provided options have been selected. // // Deprecated: Use locator-based [Locator.SelectOption] instead. Read more about [locators]. // // selector: A selector to query for. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators SelectOption(selector string, values SelectOptionValues, options ...FrameSelectOptionOptions) ([]string, error) // This method checks or unchecks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. // 3. If the element already has the right checked state, this method returns immediately. // 4. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 5. Scroll the element into view if needed. // 6. Use [Page.Mouse] to click in the center of the element. // 7. Ensure that the element is now checked or unchecked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.SetChecked] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. checked: Whether to check or uncheck the checkbox. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators SetChecked(selector string, checked bool, options ...FrameSetCheckedOptions) error // This method internally calls [document.Write()], // inheriting all its specific characteristics and behaviors. // // html: HTML markup to assign to the page. // // [document.Write()]: https://developer.mozilla.org/en-US/docs/Web/API/Document/write SetContent(html string, options ...FrameSetContentOptions) error // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then // they are resolved relative to the current working directory. For empty array, clears the selected files. // This method expects “selector” to point to an // [input element]. However, if the element is inside // the `<label>` element that has an associated // [control], targets the control instead. // // Deprecated: Use locator-based [Locator.SetInputFiles] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators SetInputFiles(selector string, files interface{}, options ...FrameSetInputFilesOptions) error // This method taps an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Touchscreen] to tap the center of the element, or the specified “position”. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** `frame.tap()` requires that the `hasTouch` option of the browser context be set to true. // // Deprecated: Use locator-based [Locator.Tap] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Tap(selector string, options ...FrameTapOptions) error // Returns `element.textContent`. // // Deprecated: Use locator-based [Locator.TextContent] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators TextContent(selector string, options ...FrameTextContentOptions) (string, error) // Returns the page title. Title() (string, error) // Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `frame.type` can be used // to send fine-grained keyboard events. To fill values in form fields, use [Frame.Fill]. // To press a special key, like `Control` or `ArrowDown`, use [Keyboard.Press]. // // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. text: A text to type into a focused element. Type(selector string, text string, options ...FrameTypeOptions) error // This method checks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is // already unchecked, this method returns immediately. // 3. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 4. Scroll the element into view if needed. // 5. Use [Page.Mouse] to click in the center of the element. // 6. Ensure that the element is now unchecked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Uncheck] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Uncheck(selector string, options ...FrameUncheckOptions) error // Returns frame's url. URL() string // Returns when the “expression” returns a truthy value, returns that value. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. WaitForFunction(expression string, arg interface{}, options ...FrameWaitForFunctionOptions) (JSHandle, error) // Waits for the required load state to be reached. // This returns when the frame reaches a required load state, `load` by default. The navigation must have been // committed when this method is called. If current document has already reached the required state, resolves // immediately. // **NOTE** Most of the time, this method is not needed because Playwright // [auto-waits before every action]. // // [auto-waits before every action]: https://playwright.dev/docs/actionability WaitForLoadState(options ...FrameWaitForLoadStateOptions) error // navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or // navigation due to History API usage, the navigation will resolve with `null`. // // Deprecated: This method is inherently racy, please use [Frame.WaitForURL] instead. // // [History API]: https://developer.mozilla.org/en-US/docs/Web/API/History_API ExpectNavigation(cb func() error, options ...FrameExpectNavigationOptions) (Response, error) // Returns when element specified by selector satisfies “state” option. Returns `null` if waiting for `hidden` or // `detached`. // **NOTE** Playwright automatically waits for element to be ready before performing an action. Using [Locator] // objects and web-first assertions make the code wait-for-selector-free. // Wait for the “selector” to satisfy “state” option (either appear/disappear from dom, or become visible/hidden). If // at the moment of calling the method “selector” already satisfies the condition, the method will return immediately. // If the selector doesn't satisfy the condition for the “timeout” milliseconds, the function will throw. // // Deprecated: Use web assertions that assert visibility or a locator-based [Locator.WaitFor] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators WaitForSelector(selector string, options ...FrameWaitForSelectorOptions) (ElementHandle, error) // Waits for the given “timeout” in milliseconds. // Note that `frame.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going // to be flaky. Use signals such as network events, selectors becoming visible and others instead. // // Deprecated: Never wait for timeout in production. Tests that wait for time are inherently flaky. Use [Locator] actions and web assertions that wait automatically. // // timeout: A timeout to wait for WaitForTimeout(timeout float64) // Waits for the frame to navigate to the given URL. // // url: A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly // equal to the string. WaitForURL(url interface{}, options ...FrameWaitForURLOptions) error }
At every point of time, page exposes its current frame tree via the [Page.MainFrame] and [Frame.ChildFrames] methods. Frame object's lifecycle is controlled by three events, dispatched on the page object:
- [Page.OnFrameAttached] - fired when the frame gets attached to the page. A Frame can be attached to the page only once.
- [Page.OnFrameNavigated] - fired when the frame commits navigation to a different URL.
- [Page.OnFrameDetached] - fired when the frame gets detached from the page. A Frame can be detached from the page only once.
An example of dumping frame tree:
type FrameAddScriptTagOptions ¶
type FrameAddScriptTagOptions struct { // Raw JavaScript content to be injected into frame. Content *string `json:"content"` // Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative // to the current working directory. Path *string `json:"path"` // Script type. Use 'module' in order to load a JavaScript ES6 module. See // [script] for more details. // // [script]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script Type *string `json:"type"` // URL of a script to be added. URL *string `json:"url"` }
type FrameAddStyleTagOptions ¶
type FrameAddStyleTagOptions struct { // Raw CSS content to be injected into frame. Content *string `json:"content"` // Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the // current working directory. Path *string `json:"path"` // URL of the `<link>` tag. URL *string `json:"url"` }
type FrameCheckOptions ¶
type FrameCheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameClickOptions ¶
type FrameClickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // defaults to 1. See [UIEvent.Detail]. ClickCount *int `json:"clickCount"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameDblclickOptions ¶
type FrameDblclickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameDispatchEventOptions ¶
type FrameDispatchEventOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameDragAndDropOptions ¶
type FrameDragAndDropOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not // specified, some visible point of the element is used. SourcePosition *Position `json:"sourcePosition"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Drops on the target element at this point relative to the top-left corner of the element's padding box. If not // specified, some visible point of the element is used. TargetPosition *Position `json:"targetPosition"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameEvalOnSelectorOptions ¶
type FrameEvalOnSelectorOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` }
type FrameExpectNavigationOptions ¶ added in v0.3700.0
type FrameExpectNavigationOptions struct { // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly // equal to the string. URL interface{} `json:"url"` // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type FrameFillOptions ¶
type FrameFillOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameFocusOptions ¶
type FrameFocusOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameGetAttributeOptions ¶
type FrameGetAttributeOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameGetByAltTextOptions ¶ added in v0.3500.0
type FrameGetByAltTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameGetByLabelOptions ¶ added in v0.3500.0
type FrameGetByLabelOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameGetByPlaceholderOptions ¶ added in v0.3500.0
type FrameGetByPlaceholderOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameGetByRoleOptions ¶ added in v0.3500.0
type FrameGetByRoleOptions struct { // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. // Learn more about [`aria-checked`]. // // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked Checked *bool `json:"checked"` // An attribute that is usually set by `aria-disabled` or `disabled`. // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about // [`aria-disabled`]. // // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled Disabled *bool `json:"disabled"` // Whether “name” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when “name” is a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` // An attribute that is usually set by `aria-expanded`. // Learn more about [`aria-expanded`]. // // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded Expanded *bool `json:"expanded"` // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as // [defined by ARIA], are matched by role selector. // Learn more about [`aria-hidden`]. // // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden IncludeHidden *bool `json:"includeHidden"` // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values // for `<h1>-<h6>` elements. // Learn more about [`aria-level`]. // // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level Level *int `json:"level"` // Option to match the [accessible name]. By default, matching is // case-insensitive and searches for a substring, use “exact” to control this behavior. // Learn more about [accessible name]. // // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name Name interface{} `json:"name"` // An attribute that is usually set by `aria-pressed`. // Learn more about [`aria-pressed`]. // // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed Pressed *bool `json:"pressed"` // An attribute that is usually set by `aria-selected`. // Learn more about [`aria-selected`]. // // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected Selected *bool `json:"selected"` }
type FrameGetByTextOptions ¶ added in v0.3500.0
type FrameGetByTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameGetByTitleOptions ¶ added in v0.3500.0
type FrameGetByTitleOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameGotoOptions ¶
type FrameGotoOptions struct { // Referer header value. If provided it will take preference over the referer header value set by // [Page.SetExtraHTTPHeaders]. Referer *string `json:"referer"` // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type FrameHoverOptions ¶
type FrameHoverOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameInnerHTMLOptions ¶
type FrameInnerHTMLOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameInnerTextOptions ¶
type FrameInnerTextOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameInputValueOptions ¶
type FrameInputValueOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameIsCheckedOptions ¶
type FrameIsCheckedOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameIsDisabledOptions ¶
type FrameIsDisabledOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameIsEditableOptions ¶
type FrameIsEditableOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameIsEnabledOptions ¶
type FrameIsEnabledOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameIsHiddenOptions ¶
type FrameIsHiddenOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // // Deprecated: This option is ignored. [Frame.IsHidden] does not wait for the element to become hidden and returns immediately. Timeout *float64 `json:"timeout"` }
type FrameIsVisibleOptions ¶
type FrameIsVisibleOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // // Deprecated: This option is ignored. [Frame.IsVisible] does not wait for the element to become visible and returns immediately. Timeout *float64 `json:"timeout"` }
type FrameLocator ¶ added in v0.3500.0
type FrameLocator interface { // Returns locator to the first matching frame. First() FrameLocator // When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements // in that iframe. // // selector: A selector to use when resolving DOM element. FrameLocator(selector string) FrameLocator // Allows locating elements by their alt text. // // text: Text to locate the element for. GetByAltText(text interface{}, options ...FrameLocatorGetByAltTextOptions) Locator // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the // `aria-label` attribute. // // text: Text to locate the element for. GetByLabel(text interface{}, options ...FrameLocatorGetByLabelOptions) Locator // Allows locating input elements by the placeholder text. // // text: Text to locate the element for. GetByPlaceholder(text interface{}, options ...FrameLocatorGetByPlaceholderOptions) Locator // Allows locating elements by their [ARIA role], // [ARIA attributes] and // [accessible name]. // // # Details // // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback // about the ARIA guidelines. // Many html elements have an implicitly [defined role] // that is recognized by the role selector. You can find all the // [supported roles here]. ARIA guidelines **do not recommend** // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. // // role: Required aria role. // // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions GetByRole(role AriaRole, options ...FrameLocatorGetByRoleOptions) Locator // Locate element by the test id. // // # Details // // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a // different test id attribute if necessary. // // testId: Id to locate the element by. GetByTestId(testId interface{}) Locator // Allows locating elements that contain given text. // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the // text content. // // # Details // // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into // one, turns line breaks into spaces and ignores leading and trailing whitespace. // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. // // text: Text to locate the element for. GetByText(text interface{}, options ...FrameLocatorGetByTextOptions) Locator // Allows locating elements by their title attribute. // // text: Text to locate the element for. GetByTitle(text interface{}, options ...FrameLocatorGetByTitleOptions) Locator // Returns locator to the last matching frame. Last() FrameLocator // The method finds an element matching the specified selector in the locator's subtree. It also accepts filter // options, similar to [Locator.Filter] method. // [Learn more about locators]. // // selectorOrLocator: A selector or locator to use when resolving DOM element. // // [Learn more about locators]: https://playwright.dev/docs/locators Locator(selectorOrLocator interface{}, options ...FrameLocatorLocatorOptions) Locator // Returns locator to the n-th matching frame. It's zero based, `nth(0)` selects the first frame. Nth(index int) FrameLocator // Returns a [Locator] object pointing to the same `iframe` as this frame locator. // Useful when you have a [FrameLocator] object obtained somewhere, and later on would like to interact with the // `iframe` element. // For a reverse operation, use [Locator.ContentFrame]. Owner() Locator }
FrameLocator represents a view to the `iframe` on the page. It captures the logic sufficient to retrieve the `iframe` and locate elements in that iframe. FrameLocator can be created with either [Page.FrameLocator] or [Locator.FrameLocator] method. **Strictness** Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches a given selector. **Converting Locator to FrameLocator** If you have a Locator object pointing to an `iframe` it can be converted to FrameLocator using [Locator.ContentFrame]. **Converting FrameLocator to Locator** If you have a FrameLocator object it can be converted to Locator pointing to the same `iframe` using [FrameLocator.Owner].
type FrameLocatorGetByAltTextOptions ¶ added in v0.3500.0
type FrameLocatorGetByAltTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameLocatorGetByLabelOptions ¶ added in v0.3500.0
type FrameLocatorGetByLabelOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameLocatorGetByPlaceholderOptions ¶ added in v0.3500.0
type FrameLocatorGetByPlaceholderOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameLocatorGetByRoleOptions ¶ added in v0.3500.0
type FrameLocatorGetByRoleOptions struct { // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. // Learn more about [`aria-checked`]. // // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked Checked *bool `json:"checked"` // An attribute that is usually set by `aria-disabled` or `disabled`. // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about // [`aria-disabled`]. // // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled Disabled *bool `json:"disabled"` // Whether “name” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when “name” is a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` // An attribute that is usually set by `aria-expanded`. // Learn more about [`aria-expanded`]. // // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded Expanded *bool `json:"expanded"` // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as // [defined by ARIA], are matched by role selector. // Learn more about [`aria-hidden`]. // // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden IncludeHidden *bool `json:"includeHidden"` // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values // for `<h1>-<h6>` elements. // Learn more about [`aria-level`]. // // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level Level *int `json:"level"` // Option to match the [accessible name]. By default, matching is // case-insensitive and searches for a substring, use “exact” to control this behavior. // Learn more about [accessible name]. // // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name Name interface{} `json:"name"` // An attribute that is usually set by `aria-pressed`. // Learn more about [`aria-pressed`]. // // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed Pressed *bool `json:"pressed"` // An attribute that is usually set by `aria-selected`. // Learn more about [`aria-selected`]. // // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected Selected *bool `json:"selected"` }
type FrameLocatorGetByTextOptions ¶ added in v0.3500.0
type FrameLocatorGetByTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameLocatorGetByTitleOptions ¶ added in v0.3500.0
type FrameLocatorGetByTitleOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type FrameLocatorLocatorOptions ¶ added in v0.2000.1
type FrameLocatorLocatorOptions struct { // Narrows down the results of the method to those which contain elements matching this relative locator. For example, // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not // the document root. For example, you can find `content` that has `div` in // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. Has Locator `json:"has"` // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. HasNot Locator `json:"hasNot"` // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. // When passed a [string], matching is case-insensitive and searches for a substring. HasNotText interface{} `json:"hasNotText"` // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches // `<article><div>Playwright</div></article>`. HasText interface{} `json:"hasText"` }
type FrameLocatorOptions ¶ added in v0.2000.1
type FrameLocatorOptions struct { // Narrows down the results of the method to those which contain elements matching this relative locator. For example, // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not // the document root. For example, you can find `content` that has `div` in // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. Has Locator `json:"has"` // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. HasNot Locator `json:"hasNot"` // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. // When passed a [string], matching is case-insensitive and searches for a substring. HasNotText interface{} `json:"hasNotText"` // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches // `<article><div>Playwright</div></article>`. HasText interface{} `json:"hasText"` }
type FramePressOptions ¶
type FramePressOptions struct { // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameQuerySelectorOptions ¶
type FrameQuerySelectorOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` }
type FrameSelectOptionOptions ¶
type FrameSelectOptionOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameSetCheckedOptions ¶
type FrameSetCheckedOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameSetContentOptions ¶
type FrameSetContentOptions struct { // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type FrameSetInputFilesOptions ¶
type FrameSetInputFilesOptions struct { // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameTapOptions ¶
type FrameTapOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameTextContentOptions ¶
type FrameTextContentOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameTypeOptions ¶
type FrameTypeOptions struct { // Time to wait between key presses in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameUncheckOptions ¶
type FrameUncheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type FrameWaitForFunctionOptions ¶
type FrameWaitForFunctionOptions struct { // If “polling” is `raf`, then “expression” is constantly executed in `requestAnimationFrame` callback. If “polling” // is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to // `raf`. Polling interface{} `json:"polling"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameWaitForLoadStateOptions ¶
type FrameWaitForLoadStateOptions struct { // Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current // document, the method resolves immediately. Can be one of: // - `load` - wait for the `load` event to be fired. // - `domcontentloaded` - wait for the `DOMContentLoaded` event to be fired. // - `networkidle` - **DISCOURAGED** wait until there are no network connections for at least `500` ms. Don't use // this method for testing, rely on web assertions to assess readiness instead. State *LoadState `json:"state"` // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameWaitForSelectorOptions ¶
type FrameWaitForSelectorOptions struct { // Defaults to `visible`. Can be either: // - `attached` - wait for element to be present in DOM. // - `detached` - wait for element to not be present in DOM. // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element // without any content or with `display:none` has an empty bounding box and is not considered visible. // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or // `visibility:hidden`. This is opposite to the `visible` option. State *WaitForSelectorState `json:"state"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type FrameWaitForURLOptions ¶
type FrameWaitForURLOptions struct { // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type Geolocation ¶ added in v0.3500.0
type HarContentPolicy ¶ added in v0.3500.0
type HarContentPolicy string
type HarMode ¶ added in v0.3500.0
type HarMode string
var ( HarModeFull *HarMode = getHarMode("full") HarModeMinimal = getHarMode("minimal") )
type HarNotFound ¶ added in v0.3500.0
type HarNotFound string
var ( HarNotFoundAbort *HarNotFound = getHarNotFound("abort") HarNotFoundFallback = getHarNotFound("fallback") )
type HttpCredentials ¶ added in v0.3500.0
type HttpCredentials struct { Username string `json:"username"` Password string `json:"password"` // Restrain sending http credentials on specific origin (scheme://host:port). Origin *string `json:"origin"` // This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests // sent from the browser. `always` - `Authorization` header with basic authentication credentials will be sent with // the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with // `WWW-Authenticate` header is received. Defaults to `unauthorized`. Send *HttpCredentialsSend `json:"send"` }
type HttpCredentialsSend ¶ added in v0.4501.0
type HttpCredentialsSend string
var ( HttpCredentialsSendAlways = getHttpCredentialsSend("always") )
type InputFile ¶
type InputFile struct { Name string `json:"name"` MimeType string `json:"mimeType,omitempty"` Buffer []byte `json:"buffer"` }
InputFile represents the input file for: - FileChooser.SetFiles() - ElementHandle.SetInputFiles() - Page.SetInputFiles()
type JSHandle ¶
type JSHandle interface { // Returns either `null` or the object handle itself, if the object handle is an instance of [ElementHandle]. AsElement() ElementHandle // The `jsHandle.dispose` method stops referencing the element handle. Dispose() error // Returns the return value of “expression”. // This method passes this handle as the first argument to “expression”. // If “expression” returns a [Promise], then `handle.evaluate` would wait for the promise to resolve and return its // value. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. Evaluate(expression string, arg ...interface{}) (interface{}, error) // Returns the return value of “expression” as a [JSHandle]. // This method passes this handle as the first argument to “expression”. // The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` // returns [JSHandle]. // If the function passed to the `jsHandle.evaluateHandle` returns a [Promise], then `jsHandle.evaluateHandle` would // wait for the promise to resolve and return its value. // See [Page.EvaluateHandle] for more details. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) // The method returns a map with **own property names** as keys and JSHandle instances for the property values. GetProperties() (map[string]JSHandle, error) // Fetches a single property from the referenced object. // // propertyName: property to get GetProperty(propertyName string) (JSHandle, error) // Returns a JSON representation of the object. If the object has a `toJSON` function, it **will not be called**. // **NOTE** The method will return an empty JSON object if the referenced object is not stringifiable. It will throw // an error if the object has circular references. JSONValue() (interface{}, error) String() string }
JSHandle represents an in-page JavaScript object. JSHandles can be created with the [Page.EvaluateHandle] method. JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with [JSHandle.Dispose]. JSHandles are auto-disposed when their origin frame gets navigated or the parent context gets destroyed. JSHandle instances can be used as an argument in [Page.EvalOnSelector], [Page.Evaluate] and [Page.EvaluateHandle] methods.
type Keyboard ¶
type Keyboard interface { // Dispatches a `keydown` event. // “key” can specify the intended // [keyboardEvent.Key] value or a single character // to generate the text for. A superset of the “key” values can be found // [here]. Examples of the keys are: // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, // etc. // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. // Holding down `Shift` will type the text that corresponds to the “key” in the upper case. // If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective // texts. // If “key” is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that // modifier active. To release the modifier key, use [Keyboard.Up]. // After the key is pressed once, subsequent calls to [Keyboard.Down] will have // [repeat] set to true. To release the key, // use [Keyboard.Up]. // **NOTE** Modifier keys DO influence `keyboard.down`. Holding down `Shift` will type the text in upper case. // // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. // // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values // [repeat]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat Down(key string) error // Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events. // // text: Sets input to the specified text value. InsertText(text string) error // **NOTE** In most cases, you should use [Locator.Press] instead. // “key” can specify the intended // [keyboardEvent.Key] value or a single character // to generate the text for. A superset of the “key” values can be found // [here]. Examples of the keys are: // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, // etc. // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. // Holding down `Shift` will type the text that corresponds to the “key” in the upper case. // If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective // texts. // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. // // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. // // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values Press(key string, options ...KeyboardPressOptions) error // **NOTE** In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is // special keyboard handling on the page - in this case use [Locator.PressSequentially]. // Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. // To press a special key, like `Control` or `ArrowDown`, use [Keyboard.Press]. // // text: A text to type into a focused element. Type(text string, options ...KeyboardTypeOptions) error // Dispatches a `keyup` event. // // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. Up(key string) error }
Keyboard provides an api for managing a virtual keyboard. The high level api is [Keyboard.Type], which takes raw characters and generates proper `keydown`, `keypress`/`input`, and `keyup` events on your page. For finer control, you can use [Keyboard.Down], [Keyboard.Up], and [Keyboard.InsertText] to manually fire events as if they were generated from a real keyboard. An example of holding down `Shift` in order to select and delete some text: An example of pressing uppercase `A` An example to trigger select-all with the keyboard
type KeyboardModifier ¶
type KeyboardModifier string
type KeyboardPressOptions ¶
type KeyboardPressOptions struct { // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` }
type KeyboardTypeOptions ¶
type KeyboardTypeOptions struct { // Time to wait between key presses in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` }
type Locator ¶ added in v0.2000.1
type Locator interface { // When the locator points to a list of elements, this returns an array of locators, pointing to their respective // elements. // **NOTE** [Locator.All] does not wait for elements to match the locator, and instead immediately returns whatever is // present in the page. When the list of elements changes dynamically, [Locator.All] will produce unpredictable and // flaky results. When the list of elements is stable, but loaded dynamically, wait for the full list to finish // loading before calling [Locator.All]. All() ([]Locator, error) // Returns an array of `node.innerText` values for all matching nodes. // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] with “useInnerText” option // to avoid flakiness. See [assertions guide] for more details. // // [assertions guide]: https://playwright.dev/docs/test-assertions AllInnerTexts() ([]string, error) // Returns an array of `node.textContent` values for all matching nodes. // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] to avoid flakiness. See // [assertions guide] for more details. // // [assertions guide]: https://playwright.dev/docs/test-assertions AllTextContents() ([]string, error) // Creates a locator that matches both this locator and the argument locator. // // locator: Additional locator to match. And(locator Locator) Locator // Calls [blur] on the element. // // [blur]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur Blur(options ...LocatorBlurOptions) error // This method returns the bounding box of the element matching the locator, or `null` if the element is not visible. // The bounding box is calculated relative to the main frame viewport - which is usually the same as the browser // window. // // # Details // // Scrolling affects the returned bounding box, similarly to // [Element.GetBoundingClientRect]. // That means `x` and/or `y` may be negative. // Elements from child frames return the bounding box relative to the main frame, unlike the // [Element.GetBoundingClientRect]. // Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the // following snippet should click the center of the element. // // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect // [Element.GetBoundingClientRect]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect BoundingBox(options ...LocatorBoundingBoxOptions) (*Rect, error) // Ensure that checkbox or radio element is checked. // // # Details // // Performs the following steps: // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already // checked, this method returns immediately. // 2. Wait for [actionability] checks on the element, unless “force” option is set. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to click in the center of the element. // 5. Ensure that the element is now checked. If not, this method throws. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // [actionability]: https://playwright.dev/docs/actionability Check(options ...LocatorCheckOptions) error // Clear the input field. // // # Details // // This method waits for [actionability] checks, focuses the element, clears it and triggers an // `input` event after clearing. // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an // error. However, if the element is inside the `<label>` element that has an associated // [control], the control will be cleared // instead. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control Clear(options ...LocatorClearOptions) error // Click an element. // // # Details // // This method clicks the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Mouse] to click in the center of the element, or the specified “position”. // 4. Wait for initiated navigations to either succeed or fail, unless “noWaitAfter” option is set. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // [actionability]: https://playwright.dev/docs/actionability Click(options ...LocatorClickOptions) error // Returns the number of elements matching the locator. // **NOTE** If you need to assert the number of elements on the page, prefer [LocatorAssertions.ToHaveCount] to avoid // flakiness. See [assertions guide] for more details. // // [assertions guide]: https://playwright.dev/docs/test-assertions Count() (int, error) // Double-click an element. // // # Details // // This method double clicks the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Mouse] to double click in the center of the element, or the specified “position”. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** `element.dblclick()` dispatches two `click` events and a single `dblclick` event. // // [actionability]: https://playwright.dev/docs/actionability Dblclick(options ...LocatorDblclickOptions) error // Programmatically dispatch an event on the matching element. // // # Details // // The snippet above dispatches the `click` event on the element. Regardless of the visibility state of the element, // `click` is dispatched. This is equivalent to calling // [element.Click()]. // Under the hood, it creates an instance of an event based on the given “type”, initializes it with “eventInit” // properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default. // Since “eventInit” is event-specific, please refer to the events documentation for the lists of initial properties: // - [DeviceMotionEvent] // - [DeviceOrientationEvent] // - [DragEvent] // - [Event] // - [FocusEvent] // - [KeyboardEvent] // - [MouseEvent] // - [PointerEvent] // - [TouchEvent] // - [WheelEvent] // You can also specify [JSHandle] as the property value if you want live objects to be passed into the event: // // 1. typ: DOM event type: `"click"`, `"dragstart"`, etc. // 2. eventInit: Optional event-specific initialization properties. // // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent DispatchEvent(typ string, eventInit interface{}, options ...LocatorDispatchEventOptions) error // Drag the source element towards the target element and drop it. // // # Details // // This method drags the locator to another target locator or target position. It will first move to the source // element, perform a `mousedown`, then move to the target element or position and perform a `mouseup`. // // target: Locator of the element to drag to. DragTo(target Locator, options ...LocatorDragToOptions) error // Resolves given locator to the first matching DOM element. If there are no matching elements, waits for one. If // multiple elements match the locator, throws. // // Deprecated: Always prefer using [Locator]s and web assertions over [ElementHandle]s because latter are inherently racy. ElementHandle(options ...LocatorElementHandleOptions) (ElementHandle, error) // Resolves given locator to all matching DOM elements. If there are no matching elements, returns an empty list. // // Deprecated: Always prefer using [Locator]s and web assertions over [ElementHandle]s because latter are inherently racy. ElementHandles() ([]ElementHandle, error) // Returns a [FrameLocator] object pointing to the same `iframe` as this locator. // Useful when you have a [Locator] object obtained somewhere, and later on would like to interact with the content // inside the frame. // For a reverse operation, use [FrameLocator.Owner]. ContentFrame() FrameLocator // Execute JavaScript code in the page, taking the matching element as an argument. // // # Details // // Returns the return value of “expression”, called with the matching element as a first argument, and “arg” as a // second argument. // If “expression” returns a [Promise], this method will wait for the promise to resolve and return its value. // If “expression” throws or rejects, this method throws. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. Evaluate(expression string, arg interface{}, options ...LocatorEvaluateOptions) (interface{}, error) // Execute JavaScript code in the page, taking all matching elements as an argument. // // # Details // // Returns the return value of “expression”, called with an array of all matching elements as a first argument, and // “arg” as a second argument. // If “expression” returns a [Promise], this method will wait for the promise to resolve and return its value. // If “expression” throws or rejects, this method throws. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. EvaluateAll(expression string, arg ...interface{}) (interface{}, error) // Execute JavaScript code in the page, taking the matching element as an argument, and return a [JSHandle] with the // result. // // # Details // // Returns the return value of “expression” as a[JSHandle], called with the matching element as a first argument, and // “arg” as a second argument. // The only difference between [Locator.Evaluate] and [Locator.EvaluateHandle] is that [Locator.EvaluateHandle] // returns [JSHandle]. // If “expression” returns a [Promise], this method will wait for the promise to resolve and return its value. // If “expression” throws or rejects, this method throws. // See [Page.EvaluateHandle] for more details. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. EvaluateHandle(expression string, arg interface{}, options ...LocatorEvaluateHandleOptions) (JSHandle, error) // Set a value to the input field. // // # Details // // This method waits for [actionability] checks, focuses the element, fills it and triggers an // `input` event after filling. Note that you can pass an empty string to clear the input field. // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an // error. However, if the element is inside the `<label>` element that has an associated // [control], the control will be filled // instead. // To send fine-grained keyboard events, use [Locator.PressSequentially]. // // value: Value to set for the `<input>`, `<textarea>` or `[contenteditable]` element. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control Fill(value string, options ...LocatorFillOptions) error // This method narrows existing locator according to the options, for example filters by text. It can be chained to // filter multiple times. Filter(options ...LocatorFilterOptions) Locator // Returns locator to the first matching element. First() Locator // Calls [focus] on the matching element. // // [focus]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus Focus(options ...LocatorFocusOptions) error // When working with iframes, you can create a frame locator that will enter the iframe and allow locating elements in // that iframe: // // selector: A selector to use when resolving DOM element. FrameLocator(selector string) FrameLocator // Returns the matching element's attribute value. // **NOTE** If you need to assert an element's attribute, prefer [LocatorAssertions.ToHaveAttribute] to avoid // flakiness. See [assertions guide] for more details. // // name: Attribute name to get the value for. // // [assertions guide]: https://playwright.dev/docs/test-assertions GetAttribute(name string, options ...LocatorGetAttributeOptions) (string, error) // Allows locating elements by their alt text. // // text: Text to locate the element for. GetByAltText(text interface{}, options ...LocatorGetByAltTextOptions) Locator // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the // `aria-label` attribute. // // text: Text to locate the element for. GetByLabel(text interface{}, options ...LocatorGetByLabelOptions) Locator // Allows locating input elements by the placeholder text. // // text: Text to locate the element for. GetByPlaceholder(text interface{}, options ...LocatorGetByPlaceholderOptions) Locator // Allows locating elements by their [ARIA role], // [ARIA attributes] and // [accessible name]. // // # Details // // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback // about the ARIA guidelines. // Many html elements have an implicitly [defined role] // that is recognized by the role selector. You can find all the // [supported roles here]. ARIA guidelines **do not recommend** // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. // // role: Required aria role. // // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions GetByRole(role AriaRole, options ...LocatorGetByRoleOptions) Locator // Locate element by the test id. // // # Details // // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a // different test id attribute if necessary. // // testId: Id to locate the element by. GetByTestId(testId interface{}) Locator // Allows locating elements that contain given text. // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the // text content. // // # Details // // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into // one, turns line breaks into spaces and ignores leading and trailing whitespace. // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. // // text: Text to locate the element for. GetByText(text interface{}, options ...LocatorGetByTextOptions) Locator // Allows locating elements by their title attribute. // // text: Text to locate the element for. GetByTitle(text interface{}, options ...LocatorGetByTitleOptions) Locator // Highlight the corresponding element(s) on the screen. Useful for debugging, don't commit the code that uses // [Locator.Highlight]. Highlight() error // Hover over the matching element. // // # Details // // This method hovers over the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Mouse] to hover over the center of the element, or the specified “position”. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // [actionability]: https://playwright.dev/docs/actionability Hover(options ...LocatorHoverOptions) error // Returns the [`element.innerHTML`]. // // [`element.innerHTML`]: https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML InnerHTML(options ...LocatorInnerHTMLOptions) (string, error) // Returns the [`element.innerText`]. // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] with “useInnerText” option // to avoid flakiness. See [assertions guide] for more details. // // [`element.innerText`]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText // [assertions guide]: https://playwright.dev/docs/test-assertions InnerText(options ...LocatorInnerTextOptions) (string, error) // Returns the value for the matching `<input>` or `<textarea>` or `<select>` element. // **NOTE** If you need to assert input value, prefer [LocatorAssertions.ToHaveValue] to avoid flakiness. See // [assertions guide] for more details. // // # Details // // Throws elements that are not an input, textarea or a select. However, if the element is inside the `<label>` // element that has an associated // [control], returns the value of the // control. // // [assertions guide]: https://playwright.dev/docs/test-assertions // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control InputValue(options ...LocatorInputValueOptions) (string, error) // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. // **NOTE** If you need to assert that checkbox is checked, prefer [LocatorAssertions.ToBeChecked] to avoid flakiness. // See [assertions guide] for more details. // // [assertions guide]: https://playwright.dev/docs/test-assertions IsChecked(options ...LocatorIsCheckedOptions) (bool, error) // Returns whether the element is disabled, the opposite of [enabled]. // **NOTE** If you need to assert that an element is disabled, prefer [LocatorAssertions.ToBeDisabled] to avoid // flakiness. See [assertions guide] for more details. // // [enabled]: https://playwright.dev/docs/actionability#enabled // [assertions guide]: https://playwright.dev/docs/test-assertions IsDisabled(options ...LocatorIsDisabledOptions) (bool, error) // Returns whether the element is [editable]. // **NOTE** If you need to assert that an element is editable, prefer [LocatorAssertions.ToBeEditable] to avoid // flakiness. See [assertions guide] for more details. // // [editable]: https://playwright.dev/docs/actionability#editable // [assertions guide]: https://playwright.dev/docs/test-assertions IsEditable(options ...LocatorIsEditableOptions) (bool, error) // Returns whether the element is [enabled]. // **NOTE** If you need to assert that an element is enabled, prefer [LocatorAssertions.ToBeEnabled] to avoid // flakiness. See [assertions guide] for more details. // // [enabled]: https://playwright.dev/docs/actionability#enabled // [assertions guide]: https://playwright.dev/docs/test-assertions IsEnabled(options ...LocatorIsEnabledOptions) (bool, error) // Returns whether the element is hidden, the opposite of [visible]. // **NOTE** If you need to assert that element is hidden, prefer [LocatorAssertions.ToBeHidden] to avoid flakiness. // See [assertions guide] for more details. // // [visible]: https://playwright.dev/docs/actionability#visible // [assertions guide]: https://playwright.dev/docs/test-assertions IsHidden(options ...LocatorIsHiddenOptions) (bool, error) // Returns whether the element is [visible]. // **NOTE** If you need to assert that element is visible, prefer [LocatorAssertions.ToBeVisible] to avoid flakiness. // See [assertions guide] for more details. // // [visible]: https://playwright.dev/docs/actionability#visible // [assertions guide]: https://playwright.dev/docs/test-assertions IsVisible(options ...LocatorIsVisibleOptions) (bool, error) // Returns locator to the last matching element. Last() Locator // The method finds an element matching the specified selector in the locator's subtree. It also accepts filter // options, similar to [Locator.Filter] method. // [Learn more about locators]. // // selectorOrLocator: A selector or locator to use when resolving DOM element. // // [Learn more about locators]: https://playwright.dev/docs/locators Locator(selectorOrLocator interface{}, options ...LocatorLocatorOptions) Locator // Returns locator to the n-th matching element. It's zero based, `nth(0)` selects the first element. Nth(index int) Locator // Creates a locator that matches either of the two locators. // // locator: Alternative locator to match. Or(locator Locator) Locator // A page this locator belongs to. Page() (Page, error) // Focuses the matching element and presses a combination of the keys. // // # Details // // Focuses the element, and then uses [Keyboard.Down] and [Keyboard.Up]. // “key” can specify the intended // [keyboardEvent.Key] value or a single character // to generate the text for. A superset of the “key” values can be found // [here]. Examples of the keys are: // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, // etc. // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. // Holding down `Shift` will type the text that corresponds to the “key” in the upper case. // If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective // texts. // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. // // key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. // // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values Press(key string, options ...LocatorPressOptions) error // **NOTE** In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is // special keyboard handling on the page. // Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the // text. // To press a special key, like `Control` or `ArrowDown`, use [Locator.Press]. // // text: String of characters to sequentially press into a focused element. PressSequentially(text string, options ...LocatorPressSequentiallyOptions) error // Take a screenshot of the element matching the locator. // // # Details // // This method captures a screenshot of the page, clipped to the size and position of a particular element matching // the locator. If the element is covered by other elements, it will not be actually visible on the screenshot. If the // element is a scrollable container, only the currently scrolled content will be visible on the screenshot. // This method waits for the [actionability] checks, then scrolls element into view before taking // a screenshot. If the element is detached from DOM, the method throws an error. // Returns the buffer with the captured screenshot. // // [actionability]: https://playwright.dev/docs/actionability Screenshot(options ...LocatorScreenshotOptions) ([]byte, error) // This method waits for [actionability] checks, then tries to scroll element into view, unless // it is completely visible as defined by // [IntersectionObserver]'s `ratio`. // See [scrolling] for alternative ways to scroll. // // [actionability]: https://playwright.dev/docs/actionability // [IntersectionObserver]: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API // [scrolling]: https://playwright.dev/docs/input#scrolling ScrollIntoViewIfNeeded(options ...LocatorScrollIntoViewIfNeededOptions) error // Selects option or options in `<select>`. // // # Details // // This method waits for [actionability] checks, waits until all specified options are present in // the `<select>` element and selects these options. // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside // the `<label>` element that has an associated // [control], the control will be used // instead. // Returns the array of option values that have been successfully selected. // Triggers a `change` and `input` event once all the provided options have been selected. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control SelectOption(values SelectOptionValues, options ...LocatorSelectOptionOptions) ([]string, error) // This method waits for [actionability] checks, then focuses the element and selects all its // text content. // If the element is inside the `<label>` element that has an associated // [control], focuses and selects text in // the control instead. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control SelectText(options ...LocatorSelectTextOptions) error // Set the state of a checkbox or a radio element. // // # Details // // This method checks or unchecks an element by performing the following steps: // 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. // 2. If the element already has the right checked state, this method returns immediately. // 3. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 4. Scroll the element into view if needed. // 5. Use [Page.Mouse] to click in the center of the element. // 6. Ensure that the element is now checked or unchecked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // checked: Whether to check or uncheck the checkbox. // // [actionability]: https://playwright.dev/docs/actionability SetChecked(checked bool, options ...LocatorSetCheckedOptions) error // Upload file or multiple files into `<input type=file>`. For inputs with a `[webkitdirectory]` attribute, only a // single directory path is supported. // // # Details // // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then // they are resolved relative to the current working directory. For empty array, clears the selected files. // This method expects [Locator] to point to an // [input element]. However, if the element is inside // the `<label>` element that has an associated // [control], targets the control instead. // // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control SetInputFiles(files interface{}, options ...LocatorSetInputFilesOptions) error // Perform a tap gesture on the element matching the locator. // // # Details // // This method taps the element by performing the following steps: // 1. Wait for [actionability] checks on the element, unless “force” option is set. // 2. Scroll the element into view if needed. // 3. Use [Page.Touchscreen] to tap the center of the element, or the specified “position”. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** `element.tap()` requires that the `hasTouch` option of the browser context be set to true. // // [actionability]: https://playwright.dev/docs/actionability Tap(options ...LocatorTapOptions) error // Returns the [`node.textContent`]. // **NOTE** If you need to assert text on the page, prefer [LocatorAssertions.ToHaveText] to avoid flakiness. See // [assertions guide] for more details. // // [`node.textContent`]: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent // [assertions guide]: https://playwright.dev/docs/test-assertions TextContent(options ...LocatorTextContentOptions) (string, error) // Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the // text. // To press a special key, like `Control` or `ArrowDown`, use [Locator.Press]. // // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. // // text: A text to type into a focused element. Type(text string, options ...LocatorTypeOptions) error // Ensure that checkbox or radio element is unchecked. // // # Details // // This method unchecks the element by performing the following steps: // 1. Ensure that element is a checkbox or a radio input. If not, this method throws. If the element is already // unchecked, this method returns immediately. // 2. Wait for [actionability] checks on the element, unless “force” option is set. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to click in the center of the element. // 5. Ensure that the element is now unchecked. If not, this method throws. // If the element is detached from the DOM at any moment during the action, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // [actionability]: https://playwright.dev/docs/actionability Uncheck(options ...LocatorUncheckOptions) error // Returns when element specified by locator satisfies the “state” option. // If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to // “timeout” milliseconds until the condition is met. WaitFor(options ...LocatorWaitForOptions) error Err() error }
Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a way to find element(s) on the page at any moment. A locator can be created with the [Page.Locator] method. Learn more about locators.
type LocatorAssertions ¶ added in v0.3500.0
type LocatorAssertions interface { // Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain // text `"error"`: Not() LocatorAssertions // Ensures that [Locator] points to an element that is // [connected] to a Document or a ShadowRoot. // // [connected]: https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected ToBeAttached(options ...LocatorAssertionsToBeAttachedOptions) error // Ensures the [Locator] points to a checked input. ToBeChecked(options ...LocatorAssertionsToBeCheckedOptions) error // Ensures the [Locator] points to a disabled element. Element is disabled if it has "disabled" attribute or is // disabled via // ['aria-disabled']. Note // that only native control elements such as HTML `button`, `input`, `select`, `textarea`, `option`, `optgroup` can be // disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored by the browser. // // ['aria-disabled']: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled ToBeDisabled(options ...LocatorAssertionsToBeDisabledOptions) error // Ensures the [Locator] points to an editable element. ToBeEditable(options ...LocatorAssertionsToBeEditableOptions) error // Ensures the [Locator] points to an empty editable element or to a DOM node that has no text. ToBeEmpty(options ...LocatorAssertionsToBeEmptyOptions) error // Ensures the [Locator] points to an enabled element. ToBeEnabled(options ...LocatorAssertionsToBeEnabledOptions) error // Ensures the [Locator] points to a focused DOM node. ToBeFocused(options ...LocatorAssertionsToBeFocusedOptions) error // Ensures that [Locator] either does not resolve to any DOM node, or resolves to a // [non-visible] one. // // [non-visible]: https://playwright.dev/docs/actionability#visible ToBeHidden(options ...LocatorAssertionsToBeHiddenOptions) error // Ensures the [Locator] points to an element that intersects viewport, according to the // [intersection observer API]. // // [intersection observer API]: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API ToBeInViewport(options ...LocatorAssertionsToBeInViewportOptions) error // Ensures that [Locator] points to an attached and [visible] DOM node. // To check that at least one element from the list is visible, use [Locator.First]. // // [visible]: https://playwright.dev/docs/actionability#visible ToBeVisible(options ...LocatorAssertionsToBeVisibleOptions) error // Ensures the [Locator] points to an element that contains the given text. All nested elements will be considered // when computing the text content of the element. You can use regular expressions for the value as well. // // # Details // // When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual // text and in the expected string before matching. When regular expression is used, the actual text is matched as is. // // expected: Expected substring or RegExp or a list of those. ToContainText(expected interface{}, options ...LocatorAssertionsToContainTextOptions) error // Ensures the [Locator] points to an element with a given // [accessible description]. // // description: Expected accessible description. // // [accessible description]: https://w3c.github.io/accname/#dfn-accessible-description ToHaveAccessibleDescription(description interface{}, options ...LocatorAssertionsToHaveAccessibleDescriptionOptions) error // Ensures the [Locator] points to an element with a given // [accessible name]. // // name: Expected accessible name. // // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name ToHaveAccessibleName(name interface{}, options ...LocatorAssertionsToHaveAccessibleNameOptions) error // Ensures the [Locator] points to an element with given attribute. // // 1. name: Attribute name. // 2. value: Expected attribute value. ToHaveAttribute(name string, value interface{}, options ...LocatorAssertionsToHaveAttributeOptions) error // Ensures the [Locator] points to an element with given CSS classes. This needs to be a full match or using a relaxed // regular expression. // // expected: Expected class or RegExp or a list of those. ToHaveClass(expected interface{}, options ...LocatorAssertionsToHaveClassOptions) error // Ensures the [Locator] resolves to an exact number of DOM nodes. // // count: Expected count. ToHaveCount(count int, options ...LocatorAssertionsToHaveCountOptions) error // Ensures the [Locator] resolves to an element with the given computed CSS style. // // 1. name: CSS property name. // 2. value: CSS property value. ToHaveCSS(name string, value interface{}, options ...LocatorAssertionsToHaveCSSOptions) error // Ensures the [Locator] points to an element with the given DOM Node ID. // // id: Element id. ToHaveId(id interface{}, options ...LocatorAssertionsToHaveIdOptions) error // Ensures the [Locator] points to an element with given JavaScript property. Note that this property can be of a // primitive type as well as a plain serializable JavaScript object. // // 1. name: Property name. // 2. value: Property value. ToHaveJSProperty(name string, value interface{}, options ...LocatorAssertionsToHaveJSPropertyOptions) error // Ensures the [Locator] points to an element with a given [ARIA role]. // Note that role is matched as a string, disregarding the ARIA role hierarchy. For example, asserting a superclass // role `"checkbox"` on an element with a subclass role `"switch"` will fail. // // role: Required aria role. // // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles ToHaveRole(role AriaRole, options ...LocatorAssertionsToHaveRoleOptions) error // Ensures the [Locator] points to an element with the given text. All nested elements will be considered when // computing the text content of the element. You can use regular expressions for the value as well. // // # Details // // When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual // text and in the expected string before matching. When regular expression is used, the actual text is matched as is. // // expected: Expected string or RegExp or a list of those. ToHaveText(expected interface{}, options ...LocatorAssertionsToHaveTextOptions) error // Ensures the [Locator] points to an element with the given input value. You can use regular expressions for the // value as well. // // value: Expected value. ToHaveValue(value interface{}, options ...LocatorAssertionsToHaveValueOptions) error // Ensures the [Locator] points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the // specified values are selected. // // values: Expected options currently selected. ToHaveValues(values []interface{}, options ...LocatorAssertionsToHaveValuesOptions) error }
The LocatorAssertions class provides assertion methods that can be used to make assertions about the Locator state in the tests.
type LocatorAssertionsToBeAttachedOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeDisabledOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeDisabledOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToBeEditableOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeEmptyOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeEmptyOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToBeEnabledOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeFocusedOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeFocusedOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToBeHiddenOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeHiddenOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToBeInViewportOptions ¶ added in v0.3500.0
type LocatorAssertionsToBeInViewportOptions struct { // The minimal ratio of the element to intersect viewport. If equals to `0`, then element should intersect viewport at // any positive ratio. Defaults to `0`. Ratio *float64 `json:"ratio"` // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToBeVisibleOptions ¶ added in v0.3500.0
type LocatorAssertionsToContainTextOptions ¶
type LocatorAssertionsToContainTextOptions struct { // Whether to perform case-insensitive match. “ignoreCase” option takes precedence over the corresponding regular // expression flag if specified. IgnoreCase *bool `json:"ignoreCase"` // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` // Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text. UseInnerText *bool `json:"useInnerText"` }
type LocatorAssertionsToHaveAccessibleDescriptionOptions ¶ added in v0.4400.1
type LocatorAssertionsToHaveAccessibleDescriptionOptions struct { // Whether to perform case-insensitive match. “ignoreCase” option takes precedence over the corresponding regular // expression flag if specified. IgnoreCase *bool `json:"ignoreCase"` // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveAccessibleNameOptions ¶ added in v0.4400.1
type LocatorAssertionsToHaveAccessibleNameOptions struct { // Whether to perform case-insensitive match. “ignoreCase” option takes precedence over the corresponding regular // expression flag if specified. IgnoreCase *bool `json:"ignoreCase"` // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveAttributeOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveAttributeOptions struct { // Whether to perform case-insensitive match. “ignoreCase” option takes precedence over the corresponding regular // expression flag if specified. IgnoreCase *bool `json:"ignoreCase"` // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveCSSOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveCSSOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveClassOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveClassOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveCountOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveCountOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveIdOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveIdOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveJSPropertyOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveJSPropertyOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveRoleOptions ¶ added in v0.4400.1
type LocatorAssertionsToHaveRoleOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveTextOptions ¶
type LocatorAssertionsToHaveTextOptions struct { // Whether to perform case-insensitive match. “ignoreCase” option takes precedence over the corresponding regular // expression flag if specified. IgnoreCase *bool `json:"ignoreCase"` // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` // Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text. UseInnerText *bool `json:"useInnerText"` }
type LocatorAssertionsToHaveValueOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveValueOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorAssertionsToHaveValuesOptions ¶ added in v0.3500.0
type LocatorAssertionsToHaveValuesOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type LocatorBlurOptions ¶ added in v0.3500.0
type LocatorBlurOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorBoundingBoxOptions ¶
type LocatorBoundingBoxOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorCheckOptions ¶
type LocatorCheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorClearOptions ¶ added in v0.3500.0
type LocatorClearOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorClickOptions ¶
type LocatorClickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // defaults to 1. See [UIEvent.Detail]. ClickCount *int `json:"clickCount"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorDblclickOptions ¶
type LocatorDblclickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorDispatchEventOptions ¶
type LocatorDispatchEventOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorDragToOptions ¶
type LocatorDragToOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not // specified, some visible point of the element is used. SourcePosition *Position `json:"sourcePosition"` // Drops on the target element at this point relative to the top-left corner of the element's padding box. If not // specified, some visible point of the element is used. TargetPosition *Position `json:"targetPosition"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorElementHandleOptions ¶
type LocatorElementHandleOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorEvaluateHandleOptions ¶
type LocatorEvaluateHandleOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorEvaluateOptions ¶
type LocatorEvaluateOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorFillOptions ¶
type LocatorFillOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorFilterOptions ¶ added in v0.3500.0
type LocatorFilterOptions struct { // Narrows down the results of the method to those which contain elements matching this relative locator. For example, // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not // the document root. For example, you can find `content` that has `div` in // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. Has Locator `json:"has"` // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. HasNot Locator `json:"hasNot"` // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. // When passed a [string], matching is case-insensitive and searches for a substring. HasNotText interface{} `json:"hasNotText"` // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches // `<article><div>Playwright</div></article>`. HasText interface{} `json:"hasText"` }
type LocatorFocusOptions ¶
type LocatorFocusOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorGetAttributeOptions ¶
type LocatorGetAttributeOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorGetByAltTextOptions ¶ added in v0.3500.0
type LocatorGetByAltTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type LocatorGetByLabelOptions ¶ added in v0.3500.0
type LocatorGetByLabelOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type LocatorGetByPlaceholderOptions ¶ added in v0.3500.0
type LocatorGetByPlaceholderOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type LocatorGetByRoleOptions ¶ added in v0.3500.0
type LocatorGetByRoleOptions struct { // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. // Learn more about [`aria-checked`]. // // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked Checked *bool `json:"checked"` // An attribute that is usually set by `aria-disabled` or `disabled`. // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about // [`aria-disabled`]. // // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled Disabled *bool `json:"disabled"` // Whether “name” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when “name” is a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` // An attribute that is usually set by `aria-expanded`. // Learn more about [`aria-expanded`]. // // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded Expanded *bool `json:"expanded"` // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as // [defined by ARIA], are matched by role selector. // Learn more about [`aria-hidden`]. // // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden IncludeHidden *bool `json:"includeHidden"` // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values // for `<h1>-<h6>` elements. // Learn more about [`aria-level`]. // // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level Level *int `json:"level"` // Option to match the [accessible name]. By default, matching is // case-insensitive and searches for a substring, use “exact” to control this behavior. // Learn more about [accessible name]. // // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name Name interface{} `json:"name"` // An attribute that is usually set by `aria-pressed`. // Learn more about [`aria-pressed`]. // // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed Pressed *bool `json:"pressed"` // An attribute that is usually set by `aria-selected`. // Learn more about [`aria-selected`]. // // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected Selected *bool `json:"selected"` }
type LocatorGetByTextOptions ¶ added in v0.3500.0
type LocatorGetByTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type LocatorGetByTitleOptions ¶ added in v0.3500.0
type LocatorGetByTitleOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type LocatorHoverOptions ¶
type LocatorHoverOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorInnerHTMLOptions ¶
type LocatorInnerHTMLOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorInnerTextOptions ¶
type LocatorInnerTextOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorInputValueOptions ¶
type LocatorInputValueOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorIsCheckedOptions ¶
type LocatorIsCheckedOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorIsDisabledOptions ¶
type LocatorIsDisabledOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorIsEditableOptions ¶
type LocatorIsEditableOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorIsEnabledOptions ¶
type LocatorIsEnabledOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorIsHiddenOptions ¶
type LocatorIsHiddenOptions struct { // // Deprecated: This option is ignored. [Locator.IsHidden] does not wait for the element to become hidden and returns immediately. Timeout *float64 `json:"timeout"` }
type LocatorIsVisibleOptions ¶
type LocatorIsVisibleOptions struct { // // Deprecated: This option is ignored. [Locator.IsVisible] does not wait for the element to become visible and returns immediately. Timeout *float64 `json:"timeout"` }
type LocatorLocatorOptions ¶ added in v0.2000.1
type LocatorLocatorOptions struct { // Narrows down the results of the method to those which contain elements matching this relative locator. For example, // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not // the document root. For example, you can find `content` that has `div` in // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. Has Locator `json:"has"` // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. HasNot Locator `json:"hasNot"` // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. // When passed a [string], matching is case-insensitive and searches for a substring. HasNotText interface{} `json:"hasNotText"` // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches // `<article><div>Playwright</div></article>`. HasText interface{} `json:"hasText"` }
type LocatorPressOptions ¶
type LocatorPressOptions struct { // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorPressSequentiallyOptions ¶ added in v0.3800.0
type LocatorPressSequentiallyOptions struct { // Time to wait between key presses in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorScreenshotOptions ¶
type LocatorScreenshotOptions struct { // When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different // treatment depending on their duration: // - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event. // - infinite animations are canceled to initial state, and then played over after the screenshot. // Defaults to `"allow"` that leaves animations untouched. Animations *ScreenshotAnimations `json:"animations"` // When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be // changed. Defaults to `"hide"`. Caret *ScreenshotCaret `json:"caret"` // Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink // box `#FF00FF` (customized by “maskColor”) that completely covers its bounding box. Mask []Locator `json:"mask"` // Specify the color of the overlay box for masked elements, in // [CSS color format]. Default color is pink `#FF00FF`. // // [CSS color format]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value MaskColor *string `json:"maskColor"` // Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. // Defaults to `false`. OmitBackground *bool `json:"omitBackground"` // The file path to save the image to. The screenshot type will be inferred from file extension. If “path” is a // relative path, then it is resolved relative to the current working directory. If no path is provided, the image // won't be saved to the disk. Path *string `json:"path"` // The quality of the image, between 0-100. Not applicable to `png` images. Quality *int `json:"quality"` // When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this // will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so // screenshots of high-dpi devices will be twice as large or even larger. // Defaults to `"device"`. Scale *ScreenshotScale `json:"scale"` // Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make // elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces // the Shadow DOM and applies to the inner frames. Style *string `json:"style"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // Specify screenshot type, defaults to `png`. Type *ScreenshotType `json:"type"` }
type LocatorScrollIntoViewIfNeededOptions ¶
type LocatorScrollIntoViewIfNeededOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorSelectOptionOptions ¶
type LocatorSelectOptionOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorSelectTextOptions ¶
type LocatorSelectTextOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorSetCheckedOptions ¶
type LocatorSetCheckedOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorSetInputFilesOptions ¶
type LocatorSetInputFilesOptions struct { // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorTapOptions ¶
type LocatorTapOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorTextContentOptions ¶
type LocatorTextContentOptions struct { // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorTypeOptions ¶
type LocatorTypeOptions struct { // Time to wait between key presses in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type LocatorUncheckOptions ¶
type LocatorUncheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type LocatorWaitForOptions ¶
type LocatorWaitForOptions struct { // Defaults to `visible`. Can be either: // - `attached` - wait for element to be present in DOM. // - `detached` - wait for element to not be present in DOM. // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element // without any content or with `display:none` has an empty bounding box and is not considered visible. // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or // `visibility:hidden`. This is opposite to the `visible` option. State *WaitForSelectorState `json:"state"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type Margin ¶ added in v0.3500.0
type Margin struct { // Top margin, accepts values labeled with units. Defaults to `0`. Top *string `json:"top"` // Right margin, accepts values labeled with units. Defaults to `0`. Right *string `json:"right"` // Bottom margin, accepts values labeled with units. Defaults to `0`. Bottom *string `json:"bottom"` // Left margin, accepts values labeled with units. Defaults to `0`. Left *string `json:"left"` }
type MixedState ¶
type MixedState string
type Mouse ¶
type Mouse interface { // Shortcut for [Mouse.Move], [Mouse.Down], [Mouse.Up]. // // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. Click(x float64, y float64, options ...MouseClickOptions) error // Shortcut for [Mouse.Move], [Mouse.Down], [Mouse.Up], [Mouse.Down] and [Mouse.Up]. // // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. Dblclick(x float64, y float64, options ...MouseDblclickOptions) error // Dispatches a `mousedown` event. Down(options ...MouseDownOptions) error // Dispatches a `mousemove` event. // // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. Move(x float64, y float64, options ...MouseMoveOptions) error // Dispatches a `mouseup` event. Up(options ...MouseUpOptions) error // Dispatches a `wheel` event. This method is usually used to manually scroll the page. See // [scrolling] for alternative ways to scroll. // **NOTE** Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling // to finish before returning. // // 1. deltaX: Pixels to scroll horizontally. // 2. deltaY: Pixels to scroll vertically. // // [scrolling]: https://playwright.dev/docs/input#scrolling Wheel(deltaX float64, deltaY float64) error }
The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Every `page` object has its own Mouse, accessible with [Page.Mouse].
type MouseButton ¶
type MouseButton string
type MouseClickOptions ¶
type MouseClickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // defaults to 1. See [UIEvent.Detail]. ClickCount *int `json:"clickCount"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` }
type MouseDblclickOptions ¶
type MouseDblclickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` }
type MouseDownOptions ¶
type MouseDownOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // defaults to 1. See [UIEvent.Detail]. ClickCount *int `json:"clickCount"` }
type MouseMoveOptions ¶
type MouseMoveOptions struct { // Defaults to 1. Sends intermediate `mousemove` events. Steps *int `json:"steps"` }
type MouseUpOptions ¶
type MouseUpOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // defaults to 1. See [UIEvent.Detail]. ClickCount *int `json:"clickCount"` }
type OptionalCookie ¶ added in v0.3500.0
type OptionalCookie struct { Name string `json:"name"` Value string `json:"value"` // Either url or domain / path are required. Optional. URL *string `json:"url"` // For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com". Either url // or domain / path are required. Optional. Domain *string `json:"domain"` // Either url or domain / path are required Optional. Path *string `json:"path"` // Unix time in seconds. Optional. Expires *float64 `json:"expires"` // Optional. HttpOnly *bool `json:"httpOnly"` // Optional. Secure *bool `json:"secure"` // Optional. SameSite *SameSiteAttribute `json:"sameSite"` }
type OptionalStorageState ¶ added in v0.3500.0
type OptionalStorageState struct { // Cookies to set for context Cookies []OptionalCookie `json:"cookies"` // localStorage to set for context Origins []Origin `json:"origins"` }
type Page ¶
type Page interface { EventEmitter // Playwright has ability to mock clock and passage of time. Clock() Clock // Emitted when the page closes. OnClose(fn func(Page)) // Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. // The arguments passed into `console.log` are available on the [ConsoleMessage] event handler argument. OnConsole(fn func(ConsoleMessage)) // Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page // crashes, ongoing and subsequent operations will throw. // The most common way to deal with crashes is to catch an exception: OnCrash(fn func(Page)) // Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** // either [Dialog.Accept] or [Dialog.Dismiss] the dialog - otherwise the page will // [freeze] waiting for the dialog, // and actions like click will never finish. // // [freeze]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking OnDialog(fn func(Dialog)) // Emitted when the JavaScript // [`DOMContentLoaded`] event is dispatched. // // [`DOMContentLoaded`]: https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded OnDOMContentLoaded(fn func(Page)) // Emitted when attachment download started. User can access basic file operations on downloaded content via the // passed [Download] instance. OnDownload(fn func(Download)) // Emitted when a file chooser is supposed to appear, such as after clicking the `<input type=file>`. Playwright can // respond to it via setting the input files using [FileChooser.SetFiles] that can be uploaded after that. OnFileChooser(fn func(FileChooser)) // Emitted when a frame is attached. OnFrameAttached(fn func(Frame)) // Emitted when a frame is detached. OnFrameDetached(fn func(Frame)) OnFrameNavigated(fn func(Frame)) // Emitted when the JavaScript [`load`] event is dispatched. // // [`load`]: https://developer.mozilla.org/en-US/docs/Web/Events/load OnLoad(fn func(Page)) // Emitted when an uncaught exception happens within the page. OnPageError(fn func(error)) // Emitted when the page opens a new tab or window. This event is emitted in addition to the [BrowserContext.OnPage], // but only for popups relevant to this page. // The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a // popup with `window.open('http://example.com')`, this event will fire when the network request to // "http://example.com" is done and its response has started loading in the popup. If you would like to route/listen // to this network request, use [BrowserContext.Route] and [BrowserContext.OnRequest] respectively instead of similar // methods on the [Page]. // **NOTE** Use [Page.WaitForLoadState] to wait until the page gets to a particular state (you should not need it in // most cases). OnPopup(fn func(Page)) // Emitted when a page issues a request. The [request] object is read-only. In order to intercept and mutate requests, // see [Page.Route] or [BrowserContext.Route]. OnRequest(fn func(Request)) // Emitted when a request fails, for example by timing out. // **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request // will complete with [Page.OnRequestFinished] event and not with [Page.OnRequestFailed]. A request will only be // considered failed when the client cannot get an HTTP response from the server, e.g. due to network error // net::ERR_FAILED. OnRequestFailed(fn func(Request)) // Emitted when a request finishes successfully after downloading the response body. For a successful response, the // sequence of events is `request`, `response` and `requestfinished`. OnRequestFinished(fn func(Request)) // Emitted when [response] status and headers are received for a request. For a successful response, the sequence of // events is `request`, `response` and `requestfinished`. OnResponse(fn func(Response)) // Emitted when [WebSocket] request is sent. OnWebSocket(fn func(WebSocket)) // Emitted when a dedicated [WebWorker] is spawned // by the page. // // [WebWorker]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API OnWorker(fn func(Worker)) // Adds a script which would be evaluated in one of the following scenarios: // - Whenever the page is navigated. // - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the // newly attached frame. // The script is evaluated after the document was created but before any of its scripts were run. This is useful to // amend the JavaScript environment, e.g. to seed `Math.random`. // // script: Script to be evaluated in the page. AddInitScript(script Script) error // Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload // fires or when the script content was injected into frame. AddScriptTag(options PageAddScriptTagOptions) (ElementHandle, error) // Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the // content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame. AddStyleTag(options PageAddStyleTagOptions) (ElementHandle, error) // Brings page to front (activates tab). BringToFront() error // This method checks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is // already checked, this method returns immediately. // 3. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 4. Scroll the element into view if needed. // 5. Use [Page.Mouse] to click in the center of the element. // 6. Ensure that the element is now checked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Check] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Check(selector string, options ...PageCheckOptions) error // This method clicks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to click in the center of the element, or the specified “position”. // 5. Wait for initiated navigations to either succeed or fail, unless “noWaitAfter” option is set. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Click] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Click(selector string, options ...PageClickOptions) error // If “runBeforeUnload” is `false`, does not run any unload handlers and waits for the page to be closed. If // “runBeforeUnload” is `true` the method will run unload handlers, but will **not** wait for the page to close. // By default, `page.close()` **does not** run `beforeunload` handlers. // **NOTE** if “runBeforeUnload” is passed as true, a `beforeunload` dialog might be summoned and should be handled // manually via [Page.OnDialog] event. Close(options ...PageCloseOptions) error // Gets the full HTML contents of the page, including the doctype. Content() (string, error) // Get the browser context that the page belongs to. Context() BrowserContext // This method double clicks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to double click in the center of the element, or the specified “position”. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** `page.dblclick()` dispatches two `click` events and a single `dblclick` event. // // Deprecated: Use locator-based [Locator.Dblclick] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Dblclick(selector string, options ...PageDblclickOptions) error // The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, // `click` is dispatched. This is equivalent to calling // [element.Click()]. // // Deprecated: Use locator-based [Locator.DispatchEvent] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. typ: DOM event type: `"click"`, `"dragstart"`, etc. // 3. eventInit: Optional event-specific initialization properties. // // [element.Click()]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click // [DeviceMotionEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent // [DeviceOrientationEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent // [DragEvent]: https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent // [Event]: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event // [FocusEvent]: https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent // [KeyboardEvent]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent // [MouseEvent]: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent // [PointerEvent]: https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent // [TouchEvent]: https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent // [WheelEvent]: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent // [locators]: https://playwright.dev/docs/locators DispatchEvent(selector string, typ string, eventInit interface{}, options ...PageDispatchEventOptions) error // This method drags the source element to the target element. It will first move to the source element, perform a // `mousedown`, then move to the target element and perform a `mouseup`. // // 1. source: A selector to search for an element to drag. If there are multiple elements satisfying the selector, the first will // be used. // 2. target: A selector to search for an element to drop onto. If there are multiple elements satisfying the selector, the first // will be used. DragAndDrop(source string, target string, options ...PageDragAndDropOptions) error // This method changes the `CSS media type` through the `media` argument, and/or the `prefers-colors-scheme` media // feature, using the `colorScheme` argument. EmulateMedia(options ...PageEmulateMediaOptions) error // The method finds an element matching the specified selector within the page and passes it as a first argument to // “expression”. If no elements match the selector, the method throws an error. Returns the value of “expression”. // If “expression” returns a [Promise], then [Page.EvalOnSelector] would wait for the promise to resolve and return // its value. // // Deprecated: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests. Use [Locator.Evaluate], other [Locator] helper methods or web-first assertions instead. // // 1. selector: A selector to query for. // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 3. arg: Optional argument to pass to “expression”. EvalOnSelector(selector string, expression string, arg interface{}, options ...PageEvalOnSelectorOptions) (interface{}, error) // The method finds all elements matching the specified selector within the page and passes an array of matched // elements as a first argument to “expression”. Returns the result of “expression” invocation. // If “expression” returns a [Promise], then [Page.EvalOnSelectorAll] would wait for the promise to resolve and return // its value. // // Deprecated: In most cases, [Locator.EvaluateAll], other [Locator] helper methods and web-first assertions do a better job. // // 1. selector: A selector to query for. // 2. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 3. arg: Optional argument to pass to “expression”. EvalOnSelectorAll(selector string, expression string, arg ...interface{}) (interface{}, error) // Returns the value of the “expression” invocation. // If the function passed to the [Page.Evaluate] returns a [Promise], then [Page.Evaluate] would wait for the promise // to resolve and return its value. // If the function passed to the [Page.Evaluate] returns a non-[Serializable] value, then [Page.Evaluate] resolves to // `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: // `-0`, `NaN`, `Infinity`, `-Infinity`. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. Evaluate(expression string, arg ...interface{}) (interface{}, error) // Returns the value of the “expression” invocation as a [JSHandle]. // The only difference between [Page.Evaluate] and [Page.EvaluateHandle] is that [Page.EvaluateHandle] returns // [JSHandle]. // If the function passed to the [Page.EvaluateHandle] returns a [Promise], then [Page.EvaluateHandle] would wait for // the promise to resolve and return its value. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) // The method adds a function called “name” on the `window` object of every frame in this page. When called, the // function executes “callback” and returns a [Promise] which resolves to the return value of “callback”. If the // “callback” returns a [Promise], it will be awaited. // The first argument of the “callback” function contains information about the caller: `{ browserContext: // BrowserContext, page: Page, frame: Frame }`. // See [BrowserContext.ExposeBinding] for the context-wide version. // **NOTE** Functions installed via [Page.ExposeBinding] survive navigations. // // 1. name: Name of the function on the window object. // 2. binding: Callback function that will be called in the Playwright's context. ExposeBinding(name string, binding BindingCallFunction, handle ...bool) error // The method adds a function called “name” on the `window` object of every frame in the page. When called, the // function executes “callback” and returns a [Promise] which resolves to the return value of “callback”. // If the “callback” returns a [Promise], it will be awaited. // See [BrowserContext.ExposeFunction] for context-wide exposed function. // **NOTE** Functions installed via [Page.ExposeFunction] survive navigations. // // 1. name: Name of the function on the window object // 2. binding: Callback function which will be called in Playwright's context. ExposeFunction(name string, binding ExposedFunction) error // This method waits for an element matching “selector”, waits for [actionability] checks, // focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string // to clear the input field. // If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an // error. However, if the element is inside the `<label>` element that has an associated // [control], the control will be filled // instead. // To send fine-grained keyboard events, use [Locator.PressSequentially]. // // Deprecated: Use locator-based [Locator.Fill] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. value: Value to fill for the `<input>`, `<textarea>` or `[contenteditable]` element. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators Fill(selector string, value string, options ...PageFillOptions) error // This method fetches an element with “selector” and focuses it. If there's no element matching “selector”, the // method waits until a matching element appears in the DOM. // // Deprecated: Use locator-based [Locator.Focus] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators Focus(selector string, options ...PageFocusOptions) error // Returns frame matching the specified criteria. Either `name` or `url` must be specified. Frame(options ...PageFrameOptions) Frame // When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements // in that iframe. // // selector: A selector to use when resolving DOM element. FrameLocator(selector string) FrameLocator // An array of all frames attached to the page. Frames() []Frame // Returns element attribute value. // // Deprecated: Use locator-based [Locator.GetAttribute] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. name: Attribute name to get the value for. // // [locators]: https://playwright.dev/docs/locators GetAttribute(selector string, name string, options ...PageGetAttributeOptions) (string, error) // Allows locating elements by their alt text. // // text: Text to locate the element for. GetByAltText(text interface{}, options ...PageGetByAltTextOptions) Locator // Allows locating input elements by the text of the associated `<label>` or `aria-labelledby` element, or by the // `aria-label` attribute. // // text: Text to locate the element for. GetByLabel(text interface{}, options ...PageGetByLabelOptions) Locator // Allows locating input elements by the placeholder text. // // text: Text to locate the element for. GetByPlaceholder(text interface{}, options ...PageGetByPlaceholderOptions) Locator // Allows locating elements by their [ARIA role], // [ARIA attributes] and // [accessible name]. // // # Details // // Role selector **does not replace** accessibility audits and conformance tests, but rather gives early feedback // about the ARIA guidelines. // Many html elements have an implicitly [defined role] // that is recognized by the role selector. You can find all the // [supported roles here]. ARIA guidelines **do not recommend** // duplicating implicit roles and attributes by setting `role` and/or `aria-*` attributes to default values. // // role: Required aria role. // // [ARIA role]: https://www.w3.org/TR/wai-aria-1.2/#roles // [ARIA attributes]: https://www.w3.org/TR/wai-aria-1.2/#aria-attributes // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [defined role]: https://w3c.github.io/html-aam/#html-element-role-mappings // [supported roles here]: https://www.w3.org/TR/wai-aria-1.2/#role_definitions GetByRole(role AriaRole, options ...PageGetByRoleOptions) Locator // Locate element by the test id. // // # Details // // By default, the `data-testid` attribute is used as a test id. Use [Selectors.SetTestIdAttribute] to configure a // different test id attribute if necessary. // // testId: Id to locate the element by. GetByTestId(testId interface{}) Locator // Allows locating elements that contain given text. // See also [Locator.Filter] that allows to match by another criteria, like an accessible role, and then filter by the // text content. // // # Details // // Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into // one, turns line breaks into spaces and ignores leading and trailing whitespace. // Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For // example, locating by text `"Log in"` matches `<input type=button value="Log in">`. // // text: Text to locate the element for. GetByText(text interface{}, options ...PageGetByTextOptions) Locator // Allows locating elements by their title attribute. // // text: Text to locate the element for. GetByTitle(text interface{}, options ...PageGetByTitleOptions) Locator // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of // the last redirect. If cannot go back, returns `null`. // Navigate to the previous page in history. GoBack(options ...PageGoBackOptions) (Response, error) // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of // the last redirect. If cannot go forward, returns `null`. // Navigate to the next page in history. GoForward(options ...PageGoForwardOptions) (Response, error) // Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first // non-redirect response. // The method will throw an error if: // - there's an SSL error (e.g. in case of self-signed certificates). // - target URL is invalid. // - the “timeout” is exceeded during navigation. // - the remote server does not respond or is unreachable. // - the main resource failed to load. // The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 // "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling // [Response.Status]. // **NOTE** The method either throws an error or returns a main resource response. The only exceptions are navigation // to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`. // **NOTE** Headless mode doesn't support navigation to a PDF document. See the // [upstream issue]. // // url: URL to navigate page to. The url should include scheme, e.g. `https://`. When a “baseURL” via the context options // was provided and the passed URL is a path, it gets merged via the // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. // // [upstream issue]: https://bugs.chromium.org/p/chromium/issues/detail?id=761295 Goto(url string, options ...PageGotoOptions) (Response, error) // This method hovers over an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Mouse] to hover over the center of the element, or the specified “position”. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Hover] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Hover(selector string, options ...PageHoverOptions) error // Returns `element.innerHTML`. // // Deprecated: Use locator-based [Locator.InnerHTML] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators InnerHTML(selector string, options ...PageInnerHTMLOptions) (string, error) // Returns `element.innerText`. // // Deprecated: Use locator-based [Locator.InnerText] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators InnerText(selector string, options ...PageInnerTextOptions) (string, error) // Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. // Throws for non-input elements. However, if the element is inside the `<label>` element that has an associated // [control], returns the value of the // control. // // Deprecated: Use locator-based [Locator.InputValue] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators InputValue(selector string, options ...PageInputValueOptions) (string, error) // Returns whether the element is checked. Throws if the element is not a checkbox or radio input. // // Deprecated: Use locator-based [Locator.IsChecked] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators IsChecked(selector string, options ...PageIsCheckedOptions) (bool, error) // Indicates that the page has been closed. IsClosed() bool // Returns whether the element is disabled, the opposite of [enabled]. // // Deprecated: Use locator-based [Locator.IsDisabled] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [enabled]: https://playwright.dev/docs/actionability#enabled // [locators]: https://playwright.dev/docs/locators IsDisabled(selector string, options ...PageIsDisabledOptions) (bool, error) // Returns whether the element is [editable]. // // Deprecated: Use locator-based [Locator.IsEditable] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [editable]: https://playwright.dev/docs/actionability#editable // [locators]: https://playwright.dev/docs/locators IsEditable(selector string, options ...PageIsEditableOptions) (bool, error) // Returns whether the element is [enabled]. // // Deprecated: Use locator-based [Locator.IsEnabled] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [enabled]: https://playwright.dev/docs/actionability#enabled // [locators]: https://playwright.dev/docs/locators IsEnabled(selector string, options ...PageIsEnabledOptions) (bool, error) // Returns whether the element is hidden, the opposite of [visible]. “selector” that // does not match any elements is considered hidden. // // Deprecated: Use locator-based [Locator.IsHidden] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [visible]: https://playwright.dev/docs/actionability#visible // [locators]: https://playwright.dev/docs/locators IsHidden(selector string, options ...PageIsHiddenOptions) (bool, error) // Returns whether the element is [visible]. “selector” that does not match any elements // is considered not visible. // // Deprecated: Use locator-based [Locator.IsVisible] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [visible]: https://playwright.dev/docs/actionability#visible // [locators]: https://playwright.dev/docs/locators IsVisible(selector string, options ...PageIsVisibleOptions) (bool, error) Keyboard() Keyboard // The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved // to the element immediately before performing an action, so a series of actions on the same locator can in fact be // performed on different DOM elements. That would happen if the DOM structure between those actions has changed. // [Learn more about locators]. // // selector: A selector to use when resolving DOM element. // // [Learn more about locators]: https://playwright.dev/docs/locators Locator(selector string, options ...PageLocatorOptions) Locator // The page's main frame. Page is guaranteed to have a main frame which persists during navigations. MainFrame() Frame Mouse() Mouse // Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`. Opener() (Page, error) // Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume' // button in the page overlay or to call `playwright.resume()` in the DevTools console. // User can inspect selectors or perform manual steps while paused. Resume will continue running the original script // from the place it was paused. // **NOTE** This method requires Playwright to be started in a headed mode, with a falsy “headless” value in the // [BrowserType.Launch]. Pause() error // Returns the PDF buffer. // **NOTE** Generating a pdf is currently only supported in Chromium headless. // `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call // [Page.EmulateMedia] before calling `page.pdf()`: // **NOTE** By default, `page.pdf()` generates a pdf with modified colors for printing. Use the // [`-webkit-print-color-adjust`] // property to force rendering of exact colors. // // [`-webkit-print-color-adjust`]: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust PDF(options ...PagePdfOptions) ([]byte, error) // Focuses the element, and then uses [Keyboard.Down] and [Keyboard.Up]. // “key” can specify the intended // [keyboardEvent.Key] value or a single character // to generate the text for. A superset of the “key” values can be found // [here]. Examples of the keys are: // `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, // `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, // etc. // Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, // `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS. // Holding down `Shift` will type the text that corresponds to the “key” in the upper case. // If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective // texts. // Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When // specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed. // // Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. // // [keyboardEvent.Key]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key // [here]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values // [locators]: https://playwright.dev/docs/locators Press(selector string, key string, options ...PagePressOptions) error // The method finds an element matching the specified selector within the page. If no elements match the selector, the // return value resolves to `null`. To wait for an element on the page, use [Locator.WaitFor]. // // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators QuerySelector(selector string, options ...PageQuerySelectorOptions) (ElementHandle, error) // The method finds all elements matching the specified selector within the page. If no elements match the selector, // the return value resolves to `[]`. // // Deprecated: Use locator-based [Page.Locator] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators QuerySelectorAll(selector string) ([]ElementHandle, error) // When testing a web page, sometimes unexpected overlays like a "Sign up" dialog appear and block actions you want to // automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time, making // them tricky to handle in automated tests. // This method lets you set up a special function, called a handler, that activates when it detects that overlay is // visible. The handler's job is to remove the overlay, allowing your test to continue as if the overlay wasn't there. // Things to keep in mind: // - When an overlay is shown predictably, we recommend explicitly waiting for it in your test and dismissing it as // a part of your normal test flow, instead of using [Page.AddLocatorHandler]. // - Playwright checks for the overlay every time before executing or retrying an action that requires an // [actionability check], or before performing an auto-waiting assertion check. When overlay // is visible, Playwright calls the handler first, and then proceeds with the action/assertion. Note that the // handler is only called when you perform an action/assertion - if the overlay becomes visible but you don't // perform any actions, the handler will not be triggered. // - After executing the handler, Playwright will ensure that overlay that triggered the handler is not visible // anymore. You can opt-out of this behavior with “noWaitAfter”. // - The execution time of the handler counts towards the timeout of the action/assertion that executed the handler. // If your handler takes too long, it might cause timeouts. // - You can register multiple handlers. However, only a single handler will be running at a time. Make sure the // actions within a handler don't depend on another handler. // **NOTE** Running the handler will alter your page state mid-test. For example it will change the currently focused // element and move the mouse. Make sure that actions that run after the handler are self-contained and do not rely on // the focus and mouse state being unchanged. <br /> <br /> For example, consider a test that calls [Locator.Focus] // followed by [Keyboard.Press]. If your handler clicks a button between these two actions, the focused element most // likely will be wrong, and key press will happen on the unexpected element. Use [Locator.Press] instead to avoid // this problem. <br /> <br /> Another example is a series of mouse actions, where [Mouse.Move] is followed by // [Mouse.Down]. Again, when the handler runs between these two actions, the mouse position will be wrong during the // mouse down. Prefer self-contained actions like [Locator.Click] that do not rely on the state being unchanged by a // handler. // // 1. locator: Locator that triggers the handler. // 2. handler: Function that should be run once “locator” appears. This function should get rid of the element that blocks actions // like click. // // [actionability check]: https://playwright.dev/docs/actionability AddLocatorHandler(locator Locator, handler func(Locator), options ...PageAddLocatorHandlerOptions) error // Removes all locator handlers added by [Page.AddLocatorHandler] for a specific locator. // // locator: Locator passed to [Page.AddLocatorHandler]. RemoveLocatorHandler(locator Locator) error // This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the // main resource response. In case of multiple redirects, the navigation will resolve with the response of the last // redirect. Reload(options ...PageReloadOptions) (Response, error) // API testing helper associated with this page. This method returns the same instance as [BrowserContext.Request] on // the page's context. See [BrowserContext.Request] for more details. Request() APIRequestContext // Routing provides the capability to modify network requests that are made by a page. // Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or // aborted. // **NOTE** The handler will only be called for the first url if the response is a redirect. // **NOTE** [Page.Route] will not intercept requests intercepted by Service Worker. See // [this] issue. We recommend disabling Service Workers when // using request interception by setting “Browser.newContext.serviceWorkers” to `block`. // **NOTE** [Page.Route] will not intercept the first request of a popup page. Use [BrowserContext.Route] instead. // // 1. url: A glob pattern, regex pattern or predicate receiving [URL] to match while routing. When a “baseURL” via the context // options was provided and the passed URL is a path, it gets merged via the // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. // 2. handler: handler function to route the request. // // [this]: https://github.com/microsoft/playwright/issues/1090 Route(url interface{}, handler routeHandler, times ...int) error // If specified the network requests that are made in the page will be served from the HAR file. Read more about // [Replaying from HAR]. // Playwright will not serve requests intercepted by Service Worker from the HAR file. See // [this] issue. We recommend disabling Service Workers when // using request interception by setting “Browser.newContext.serviceWorkers” to `block`. // // har: Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a // relative path, then it is resolved relative to the current working directory. // // [Replaying from HAR]: https://playwright.dev/docs/mock#replaying-from-har // [this]: https://github.com/microsoft/playwright/issues/1090 RouteFromHAR(har string, options ...PageRouteFromHAROptions) error // Returns the buffer with the captured screenshot. Screenshot(options ...PageScreenshotOptions) ([]byte, error) // This method waits for an element matching “selector”, waits for [actionability] checks, waits // until all specified options are present in the `<select>` element and selects these options. // If the target element is not a `<select>` element, this method throws an error. However, if the element is inside // the `<label>` element that has an associated // [control], the control will be used // instead. // Returns the array of option values that have been successfully selected. // Triggers a `change` and `input` event once all the provided options have been selected. // // Deprecated: Use locator-based [Locator.SelectOption] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators SelectOption(selector string, values SelectOptionValues, options ...PageSelectOptionOptions) ([]string, error) // This method checks or unchecks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. // 3. If the element already has the right checked state, this method returns immediately. // 4. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 5. Scroll the element into view if needed. // 6. Use [Page.Mouse] to click in the center of the element. // 7. Ensure that the element is now checked or unchecked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.SetChecked] instead. Read more about [locators]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. checked: Whether to check or uncheck the checkbox. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators SetChecked(selector string, checked bool, options ...PageSetCheckedOptions) error // This method internally calls [document.Write()], // inheriting all its specific characteristics and behaviors. // // html: HTML markup to assign to the page. // // [document.Write()]: https://developer.mozilla.org/en-US/docs/Web/API/Document/write SetContent(html string, options ...PageSetContentOptions) error // - [Page.GoBack] // - [Page.GoForward] // - [Page.Goto] // - [Page.Reload] // - [Page.SetContent] // - [Page.ExpectNavigation] // - [Page.WaitForURL] // **NOTE** [Page.SetDefaultNavigationTimeout] takes priority over [Page.SetDefaultTimeout], // [BrowserContext.SetDefaultTimeout] and [BrowserContext.SetDefaultNavigationTimeout]. // // timeout: Maximum navigation time in milliseconds SetDefaultNavigationTimeout(timeout float64) // This setting will change the default maximum time for all the methods accepting “timeout” option. // **NOTE** [Page.SetDefaultNavigationTimeout] takes priority over [Page.SetDefaultTimeout]. // // timeout: Maximum time in milliseconds SetDefaultTimeout(timeout float64) // The extra HTTP headers will be sent with every request the page initiates. // **NOTE** [Page.SetExtraHTTPHeaders] does not guarantee the order of headers in the outgoing requests. // // headers: An object containing additional HTTP headers to be sent with every request. All header values must be strings. SetExtraHTTPHeaders(headers map[string]string) error // Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then // they are resolved relative to the current working directory. For empty array, clears the selected files. For inputs // with a `[webkitdirectory]` attribute, only a single directory path is supported. // This method expects “selector” to point to an // [input element]. However, if the element is inside // the `<label>` element that has an associated // [control], targets the control instead. // // Deprecated: Use locator-based [Locator.SetInputFiles] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [input element]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input // [control]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control // [locators]: https://playwright.dev/docs/locators SetInputFiles(selector string, files interface{}, options ...PageSetInputFilesOptions) error // In the case of multiple pages in a single browser, each page can have its own viewport size. However, // [Browser.NewContext] allows to set viewport size (and more) for all pages in the context at once. // [Page.SetViewportSize] will resize the page. A lot of websites don't expect phones to change size, so you should // set the viewport size before navigating to the page. [Page.SetViewportSize] will also reset `screen` size, use // [Browser.NewContext] with `screen` and `viewport` parameters if you need better control of these properties. SetViewportSize(width int, height int) error // This method taps an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 3. Scroll the element into view if needed. // 4. Use [Page.Touchscreen] to tap the center of the element, or the specified “position”. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // **NOTE** [Page.Tap] the method will throw if “hasTouch” option of the browser context is false. // // Deprecated: Use locator-based [Locator.Tap] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Tap(selector string, options ...PageTapOptions) error // Returns `element.textContent`. // // Deprecated: Use locator-based [Locator.TextContent] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [locators]: https://playwright.dev/docs/locators TextContent(selector string, options ...PageTextContentOptions) (string, error) // Returns the page's title. Title() (string, error) Touchscreen() Touchscreen // Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to // send fine-grained keyboard events. To fill values in form fields, use [Page.Fill]. // To press a special key, like `Control` or `ArrowDown`, use [Keyboard.Press]. // // Deprecated: In most cases, you should use [Locator.Fill] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [Locator.PressSequentially]. // // 1. selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // 2. text: A text to type into a focused element. Type(selector string, text string, options ...PageTypeOptions) error // This method unchecks an element matching “selector” by performing the following steps: // 1. Find an element matching “selector”. If there is none, wait until a matching element is attached to the DOM. // 2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is // already unchecked, this method returns immediately. // 3. Wait for [actionability] checks on the matched element, unless “force” option is set. If // the element is detached during the checks, the whole action is retried. // 4. Scroll the element into view if needed. // 5. Use [Page.Mouse] to click in the center of the element. // 6. Ensure that the element is now unchecked. If not, this method throws. // When all steps combined have not finished during the specified “timeout”, this method throws a [TimeoutError]. // Passing zero timeout disables this. // // Deprecated: Use locator-based [Locator.Uncheck] instead. Read more about [locators]. // // selector: A selector to search for an element. If there are multiple elements satisfying the selector, the first will be // used. // // [actionability]: https://playwright.dev/docs/actionability // [locators]: https://playwright.dev/docs/locators Uncheck(selector string, options ...PageUncheckOptions) error // Removes all routes created with [Page.Route] and [Page.RouteFromHAR]. UnrouteAll(options ...PageUnrouteAllOptions) error // Removes a route created with [Page.Route]. When “handler” is not specified, removes all routes for the “url”. // // 1. url: A glob pattern, regex pattern or predicate receiving [URL] to match while routing. // 2. handler: Optional handler function to route the request. Unroute(url interface{}, handler ...routeHandler) error URL() string // Video object associated with this page. Video() Video ViewportSize() *Size // Performs action and waits for a [ConsoleMessage] to be logged by in the page. If predicate is provided, it passes // [ConsoleMessage] value into the `predicate` function and waits for `predicate(message)` to return a truthy value. // Will throw an error if the page is closed before the [Page.OnConsole] event is fired. ExpectConsoleMessage(cb func() error, options ...PageExpectConsoleMessageOptions) (ConsoleMessage, error) // Performs action and waits for a new [Download]. If predicate is provided, it passes [Download] value into the // `predicate` function and waits for `predicate(download)` to return a truthy value. Will throw an error if the page // is closed before the download event is fired. ExpectDownload(cb func() error, options ...PageExpectDownloadOptions) (Download, error) // Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy // value. Will throw an error if the page is closed before the event is fired. Returns the event data value. // // event: Event name, same one typically passed into `*.on(event)`. ExpectEvent(event string, cb func() error, options ...PageExpectEventOptions) (interface{}, error) // Performs action and waits for a new [FileChooser] to be created. If predicate is provided, it passes [FileChooser] // value into the `predicate` function and waits for `predicate(fileChooser)` to return a truthy value. Will throw an // error if the page is closed before the file chooser is opened. ExpectFileChooser(cb func() error, options ...PageExpectFileChooserOptions) (FileChooser, error) // Returns when the “expression” returns a truthy value. It resolves to a JSHandle of the truthy value. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. WaitForFunction(expression string, arg interface{}, options ...PageWaitForFunctionOptions) (JSHandle, error) // Returns when the required load state has been reached. // This resolves when the page reaches a required load state, `load` by default. The navigation must have been // committed when this method is called. If current document has already reached the required state, resolves // immediately. // **NOTE** Most of the time, this method is not needed because Playwright // [auto-waits before every action]. // // [auto-waits before every action]: https://playwright.dev/docs/actionability WaitForLoadState(options ...PageWaitForLoadStateOptions) error // navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or // navigation due to History API usage, the navigation will resolve with `null`. // // Deprecated: This method is inherently racy, please use [Page.WaitForURL] instead. // // [History API]: https://developer.mozilla.org/en-US/docs/Web/API/History_API ExpectNavigation(cb func() error, options ...PageExpectNavigationOptions) (Response, error) // Performs action and waits for a popup [Page]. If predicate is provided, it passes [Popup] value into the // `predicate` function and waits for `predicate(page)` to return a truthy value. Will throw an error if the page is // closed before the popup event is fired. ExpectPopup(cb func() error, options ...PageExpectPopupOptions) (Page, error) // Waits for the matching request and returns it. See [waiting for event] for more // details about events. // // urlOrPredicate: Request URL string, regex or predicate receiving [Request] object. When a “baseURL” via the context options was // provided and the passed URL is a path, it gets merged via the // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. // // [waiting for event]: https://playwright.dev/docs/events#waiting-for-event ExpectRequest(urlOrPredicate interface{}, cb func() error, options ...PageExpectRequestOptions) (Request, error) // Performs action and waits for a [Request] to finish loading. If predicate is provided, it passes [Request] value // into the `predicate` function and waits for `predicate(request)` to return a truthy value. Will throw an error if // the page is closed before the [Page.OnRequestFinished] event is fired. ExpectRequestFinished(cb func() error, options ...PageExpectRequestFinishedOptions) (Request, error) // Returns the matched response. See [waiting for event] for more details about // events. // // urlOrPredicate: Request URL string, regex or predicate receiving [Response] object. When a “baseURL” via the context options was // provided and the passed URL is a path, it gets merged via the // [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. // // [waiting for event]: https://playwright.dev/docs/events#waiting-for-event ExpectResponse(urlOrPredicate interface{}, cb func() error, options ...PageExpectResponseOptions) (Response, error) // Returns when element specified by selector satisfies “state” option. Returns `null` if waiting for `hidden` or // `detached`. // **NOTE** Playwright automatically waits for element to be ready before performing an action. Using [Locator] // objects and web-first assertions makes the code wait-for-selector-free. // Wait for the “selector” to satisfy “state” option (either appear/disappear from dom, or become visible/hidden). If // at the moment of calling the method “selector” already satisfies the condition, the method will return immediately. // If the selector doesn't satisfy the condition for the “timeout” milliseconds, the function will throw. // // Deprecated: Use web assertions that assert visibility or a locator-based [Locator.WaitFor] instead. Read more about [locators]. // // selector: A selector to query for. // // [locators]: https://playwright.dev/docs/locators WaitForSelector(selector string, options ...PageWaitForSelectorOptions) (ElementHandle, error) // Waits for the given “timeout” in milliseconds. // Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going // to be flaky. Use signals such as network events, selectors becoming visible and others instead. // // Deprecated: Never wait for timeout in production. Tests that wait for time are inherently flaky. Use [Locator] actions and web assertions that wait automatically. // // timeout: A timeout to wait for WaitForTimeout(timeout float64) // Waits for the main frame to navigate to the given URL. // // url: A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly // equal to the string. WaitForURL(url interface{}, options ...PageWaitForURLOptions) error // Performs action and waits for a new [WebSocket]. If predicate is provided, it passes [WebSocket] value into the // `predicate` function and waits for `predicate(webSocket)` to return a truthy value. Will throw an error if the page // is closed before the WebSocket event is fired. ExpectWebSocket(cb func() error, options ...PageExpectWebSocketOptions) (WebSocket, error) // Performs action and waits for a new [Worker]. If predicate is provided, it passes [Worker] value into the // `predicate` function and waits for `predicate(worker)` to return a truthy value. Will throw an error if the page is // closed before the worker event is fired. ExpectWorker(cb func() error, options ...PageExpectWorkerOptions) (Worker, error) // This method returns all of the dedicated // [WebWorkers] associated with the page. // **NOTE** This does not contain ServiceWorkers // // [WebWorkers]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API Workers() []Worker // **NOTE** In most cases, you should use [Page.ExpectEvent]. // Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function // and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is closed before the // `event` is fired. // // event: Event name, same one typically passed into `*.on(event)`. WaitForEvent(event string, options ...PageWaitForEventOptions) (interface{}, error) }
Page provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. One Browser instance might have multiple Page instances. This example creates a page, navigates it to a URL, and then saves a screenshot: The Page class emits various events (described below) which can be handled using any of Node's native `EventEmitter` methods, such as `on`, `once` or `removeListener`. This example logs a message for a single page `load` event: To unsubscribe from events use the `removeListener` method:
type PageAddLocatorHandlerOptions ¶ added in v0.4400.1
type PageAddLocatorHandlerOptions struct { // By default, after calling the handler Playwright will wait until the overlay becomes hidden, and only then // Playwright will continue with the action/assertion that triggered the handler. This option allows to opt-out of // this behavior, so that overlay can stay visible after the handler has run. NoWaitAfter *bool `json:"noWaitAfter"` // Specifies the maximum number of times this handler should be called. Unlimited by default. Times *int `json:"times"` }
type PageAddScriptTagOptions ¶
type PageAddScriptTagOptions struct { // Raw JavaScript content to be injected into frame. Content *string `json:"content"` // Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative // to the current working directory. Path *string `json:"path"` // Script type. Use 'module' in order to load a JavaScript ES6 module. See // [script] for more details. // // [script]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script Type *string `json:"type"` // URL of a script to be added. URL *string `json:"url"` }
type PageAddStyleTagOptions ¶
type PageAddStyleTagOptions struct { // Raw CSS content to be injected into frame. Content *string `json:"content"` // Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to the // current working directory. Path *string `json:"path"` // URL of the `<link>` tag. URL *string `json:"url"` }
type PageAssertions ¶ added in v0.3500.0
type PageAssertions interface { // Makes the assertion check for the opposite condition. For example, this code tests that the page URL doesn't // contain `"error"`: Not() PageAssertions // Ensures the page has the given title. // // titleOrRegExp: Expected title or RegExp. ToHaveTitle(titleOrRegExp interface{}, options ...PageAssertionsToHaveTitleOptions) error // Ensures the page is navigated to the given URL. // // urlOrRegExp: Expected URL string or RegExp. ToHaveURL(urlOrRegExp interface{}, options ...PageAssertionsToHaveURLOptions) error }
The PageAssertions class provides assertion methods that can be used to make assertions about the Page state in the tests.
type PageAssertionsToHaveTitleOptions ¶ added in v0.3500.0
type PageAssertionsToHaveTitleOptions struct { // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type PageAssertionsToHaveURLOptions ¶ added in v0.3500.0
type PageAssertionsToHaveURLOptions struct { // Whether to perform case-insensitive match. “ignoreCase” option takes precedence over the corresponding regular // expression flag if specified. IgnoreCase *bool `json:"ignoreCase"` // Time to retry the assertion for in milliseconds. Defaults to `5000`. Timeout *float64 `json:"timeout"` }
type PageCheckOptions ¶
type PageCheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageClickOptions ¶
type PageClickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // defaults to 1. See [UIEvent.Detail]. ClickCount *int `json:"clickCount"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageCloseOptions ¶
type PageCloseOptions struct { // The reason to be reported to the operations interrupted by the page closure. Reason *string `json:"reason"` // Defaults to `false`. Whether to run the // [before unload] page handlers. // // [before unload]: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload RunBeforeUnload *bool `json:"runBeforeUnload"` }
type PageDblclickOptions ¶
type PageDblclickOptions struct { // Defaults to `left`. Button *MouseButton `json:"button"` // Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageDispatchEventOptions ¶
type PageDispatchEventOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageDragAndDropOptions ¶
type PageDragAndDropOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // Clicks on the source element at this point relative to the top-left corner of the element's padding box. If not // specified, some visible point of the element is used. SourcePosition *Position `json:"sourcePosition"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Drops on the target element at this point relative to the top-left corner of the element's padding box. If not // specified, some visible point of the element is used. TargetPosition *Position `json:"targetPosition"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageEmulateMediaOptions ¶
type PageEmulateMediaOptions struct { // Emulates `prefers-colors-scheme` media feature, supported values are `light`, `dark`, `no-preference`. // Passing `no-override` disables color scheme emulation. ColorScheme *ColorScheme `json:"colorScheme"` ForcedColors *ForcedColors `json:"forcedColors"` // Changes the CSS media type of the page. The only allowed values are `screen`, `print` and `no-override`. // Passing `no-override` disables CSS media emulation. Media *Media `json:"media"` // Emulates `prefers-reduced-motion` media feature, supported values are `reduce`, `no-preference`. Passing // `no-override` disables reduced motion emulation. ReducedMotion *ReducedMotion `json:"reducedMotion"` }
type PageEvalOnSelectorOptions ¶
type PageEvalOnSelectorOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` }
type PageExpectConsoleMessageOptions ¶ added in v0.3500.0
type PageExpectConsoleMessageOptions struct { // Receives the [ConsoleMessage] object and resolves to truthy value when the waiting should resolve. Predicate func(ConsoleMessage) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageExpectDownloadOptions ¶ added in v0.3500.0
type PageExpectDownloadOptions struct { // Receives the [Download] object and resolves to truthy value when the waiting should resolve. Predicate func(Download) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageExpectEventOptions ¶ added in v0.3500.0
type PageExpectEventOptions struct { // Receives the event data and resolves to truthy value when the waiting should resolve. Predicate interface{} `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageExpectFileChooserOptions ¶ added in v0.3500.0
type PageExpectFileChooserOptions struct { // Receives the [FileChooser] object and resolves to truthy value when the waiting should resolve. Predicate func(FileChooser) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageExpectNavigationOptions ¶ added in v0.3700.0
type PageExpectNavigationOptions struct { // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly // equal to the string. URL interface{} `json:"url"` // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type PageExpectPopupOptions ¶ added in v0.3500.0
type PageExpectPopupOptions struct { // Receives the [Page] object and resolves to truthy value when the waiting should resolve. Predicate func(Page) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageExpectRequestFinishedOptions ¶ added in v0.3500.0
type PageExpectRequestFinishedOptions struct { // Receives the [Request] object and resolves to truthy value when the waiting should resolve. Predicate func(Request) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageExpectRequestOptions ¶ added in v0.3700.0
type PageExpectRequestOptions struct { // Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can // be changed by using the [Page.SetDefaultTimeout] method. Timeout *float64 `json:"timeout"` }
type PageExpectResponseOptions ¶ added in v0.3700.0
type PageExpectResponseOptions struct { // Maximum wait time in milliseconds, defaults to 30 seconds, pass `0` to disable the timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageExpectWebSocketOptions ¶ added in v0.3500.0
type PageExpectWebSocketOptions struct { // Receives the [WebSocket] object and resolves to truthy value when the waiting should resolve. Predicate func(WebSocket) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageExpectWorkerOptions ¶ added in v0.3500.0
type PageExpectWorkerOptions struct { // Receives the [Worker] object and resolves to truthy value when the waiting should resolve. Predicate func(Worker) bool `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageFillOptions ¶
type PageFillOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageFocusOptions ¶
type PageFocusOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageFrameOptions ¶
type PageFrameOptions struct { // Frame name specified in the `iframe`'s `name` attribute. Optional. Name *string `json:"name"` // A glob pattern, regex pattern or predicate receiving frame's `url` as a [URL] object. Optional. URL interface{} `json:"url"` }
type PageGetAttributeOptions ¶
type PageGetAttributeOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageGetByAltTextOptions ¶ added in v0.3500.0
type PageGetByAltTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type PageGetByLabelOptions ¶ added in v0.3500.0
type PageGetByLabelOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type PageGetByPlaceholderOptions ¶ added in v0.3500.0
type PageGetByPlaceholderOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type PageGetByRoleOptions ¶ added in v0.3500.0
type PageGetByRoleOptions struct { // An attribute that is usually set by `aria-checked` or native `<input type=checkbox>` controls. // Learn more about [`aria-checked`]. // // [`aria-checked`]: https://www.w3.org/TR/wai-aria-1.2/#aria-checked Checked *bool `json:"checked"` // An attribute that is usually set by `aria-disabled` or `disabled`. // **NOTE** Unlike most other attributes, `disabled` is inherited through the DOM hierarchy. Learn more about // [`aria-disabled`]. // // [`aria-disabled`]: https://www.w3.org/TR/wai-aria-1.2/#aria-disabled Disabled *bool `json:"disabled"` // Whether “name” is matched exactly: case-sensitive and whole-string. Defaults to false. Ignored when “name” is a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` // An attribute that is usually set by `aria-expanded`. // Learn more about [`aria-expanded`]. // // [`aria-expanded`]: https://www.w3.org/TR/wai-aria-1.2/#aria-expanded Expanded *bool `json:"expanded"` // Option that controls whether hidden elements are matched. By default, only non-hidden elements, as // [defined by ARIA], are matched by role selector. // Learn more about [`aria-hidden`]. // // [defined by ARIA]: https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion // [`aria-hidden`]: https://www.w3.org/TR/wai-aria-1.2/#aria-hidden IncludeHidden *bool `json:"includeHidden"` // A number attribute that is usually present for roles `heading`, `listitem`, `row`, `treeitem`, with default values // for `<h1>-<h6>` elements. // Learn more about [`aria-level`]. // // [`aria-level`]: https://www.w3.org/TR/wai-aria-1.2/#aria-level Level *int `json:"level"` // Option to match the [accessible name]. By default, matching is // case-insensitive and searches for a substring, use “exact” to control this behavior. // Learn more about [accessible name]. // // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name // [accessible name]: https://w3c.github.io/accname/#dfn-accessible-name Name interface{} `json:"name"` // An attribute that is usually set by `aria-pressed`. // Learn more about [`aria-pressed`]. // // [`aria-pressed`]: https://www.w3.org/TR/wai-aria-1.2/#aria-pressed Pressed *bool `json:"pressed"` // An attribute that is usually set by `aria-selected`. // Learn more about [`aria-selected`]. // // [`aria-selected`]: https://www.w3.org/TR/wai-aria-1.2/#aria-selected Selected *bool `json:"selected"` }
type PageGetByTextOptions ¶ added in v0.3500.0
type PageGetByTextOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type PageGetByTitleOptions ¶ added in v0.3500.0
type PageGetByTitleOptions struct { // Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a // regular expression. Note that exact match still trims whitespace. Exact *bool `json:"exact"` }
type PageGoBackOptions ¶
type PageGoBackOptions struct { // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type PageGoForwardOptions ¶
type PageGoForwardOptions struct { // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type PageGotoOptions ¶
type PageGotoOptions struct { // Referer header value. If provided it will take preference over the referer header value set by // [Page.SetExtraHTTPHeaders]. Referer *string `json:"referer"` // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type PageHoverOptions ¶
type PageHoverOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageInnerHTMLOptions ¶
type PageInnerHTMLOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageInnerTextOptions ¶
type PageInnerTextOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageInputValueOptions ¶
type PageInputValueOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageIsCheckedOptions ¶
type PageIsCheckedOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageIsDisabledOptions ¶
type PageIsDisabledOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageIsEditableOptions ¶
type PageIsEditableOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageIsEnabledOptions ¶
type PageIsEnabledOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageIsHiddenOptions ¶
type PageIsHiddenOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // // Deprecated: This option is ignored. [Page.IsHidden] does not wait for the element to become hidden and returns immediately. Timeout *float64 `json:"timeout"` }
type PageIsVisibleOptions ¶
type PageIsVisibleOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // // Deprecated: This option is ignored. [Page.IsVisible] does not wait for the element to become visible and returns immediately. Timeout *float64 `json:"timeout"` }
type PageLocatorOptions ¶ added in v0.2000.1
type PageLocatorOptions struct { // Narrows down the results of the method to those which contain elements matching this relative locator. For example, // `article` that has `text=Playwright` matches `<article><div>Playwright</div></article>`. // Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not // the document root. For example, you can find `content` that has `div` in // `<article><content><div>Playwright</div></content></article>`. However, looking for `content` that has `article // div` will fail, because the inner locator must be relative and should not use any elements outside the `content`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. Has Locator `json:"has"` // Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the // outer one. For example, `article` that does not have `div` matches `<article><span>Playwright</span></article>`. // Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator]s. HasNot Locator `json:"hasNot"` // Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. // When passed a [string], matching is case-insensitive and searches for a substring. HasNotText interface{} `json:"hasNotText"` // Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When // passed a [string], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches // `<article><div>Playwright</div></article>`. HasText interface{} `json:"hasText"` }
type PagePdfOptions ¶
type PagePdfOptions struct { bool `json:"displayHeaderFooter"` FooterTemplate *string `json:"footerTemplate"` // Paper format. If set, takes priority over “width” or “height” options. Defaults to 'Letter'. Format *string `json:"format"` // HTML template for the print header. Should be valid HTML markup with following classes used to inject printing // values into them: // - `date` formatted print date // - `title` document title // - `url` document location // - `pageNumber` current page number // - `totalPages` total pages in the document HeaderTemplate *string `json:"headerTemplate"` // Paper height, accepts values labeled with units. Height *string `json:"height"` // Paper orientation. Defaults to `false`. Landscape *bool `json:"landscape"` // Paper margins, defaults to none. Margin *Margin `json:"margin"` // Whether or not to embed the document outline into the PDF. Defaults to `false`. Outline *bool `json:"outline"` // Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages. PageRanges *string `json:"pageRanges"` // The file path to save the PDF to. If “path” is a relative path, then it is resolved relative to the current working // directory. If no path is provided, the PDF won't be saved to the disk. Path *string `json:"path"` // Give any CSS `@page` size declared in the page priority over what is declared in “width” and “height” or “format” // options. Defaults to `false`, which will scale the content to fit the paper size. PreferCSSPageSize *bool `json:"preferCSSPageSize"` // Print background graphics. Defaults to `false`. PrintBackground *bool `json:"printBackground"` // Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2. Scale *float64 `json:"scale"` // Whether or not to generate tagged (accessible) PDF. Defaults to `false`. Tagged *bool `json:"tagged"` // Paper width, accepts values labeled with units. Width *string `json:"width"` }DisplayHeaderFooter *
type PagePressOptions ¶
type PagePressOptions struct { // Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You // can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as // navigating to inaccessible pages. Defaults to `false`. // // Deprecated: This option will default to `true` in the future. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageQuerySelectorOptions ¶
type PageQuerySelectorOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` }
type PageReloadOptions ¶
type PageReloadOptions struct { // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type PageRouteFromHAROptions ¶ added in v0.3500.0
type PageRouteFromHAROptions struct { // - If set to 'abort' any request not found in the HAR file will be aborted. // - If set to 'fallback' missing requests will be sent to the network. // Defaults to abort. NotFound *HarNotFound `json:"notFound"` // If specified, updates the given HAR with the actual network information instead of serving from file. The file is // written to disk when [BrowserContext.Close] is called. Update *bool `json:"update"` // Optional setting to control resource content management. If `attach` is specified, resources are persisted as // separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. UpdateContent *RouteFromHarUpdateContentPolicy `json:"updateContent"` // When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, // cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to // `minimal`. UpdateMode *HarMode `json:"updateMode"` // A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the // pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. URL interface{} `json:"url"` }
type PageScreenshotOptions ¶
type PageScreenshotOptions struct { // When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different // treatment depending on their duration: // - finite animations are fast-forwarded to completion, so they'll fire `transitionend` event. // - infinite animations are canceled to initial state, and then played over after the screenshot. // Defaults to `"allow"` that leaves animations untouched. Animations *ScreenshotAnimations `json:"animations"` // When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be // changed. Defaults to `"hide"`. Caret *ScreenshotCaret `json:"caret"` // An object which specifies clipping of the resulting image. Clip *Rect `json:"clip"` // When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to // `false`. FullPage *bool `json:"fullPage"` // Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink // box `#FF00FF` (customized by “maskColor”) that completely covers its bounding box. Mask []Locator `json:"mask"` // Specify the color of the overlay box for masked elements, in // [CSS color format]. Default color is pink `#FF00FF`. // // [CSS color format]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value MaskColor *string `json:"maskColor"` // Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. // Defaults to `false`. OmitBackground *bool `json:"omitBackground"` // The file path to save the image to. The screenshot type will be inferred from file extension. If “path” is a // relative path, then it is resolved relative to the current working directory. If no path is provided, the image // won't be saved to the disk. Path *string `json:"path"` // The quality of the image, between 0-100. Not applicable to `png` images. Quality *int `json:"quality"` // When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this // will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so // screenshots of high-dpi devices will be twice as large or even larger. // Defaults to `"device"`. Scale *ScreenshotScale `json:"scale"` // Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make // elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces // the Shadow DOM and applies to the inner frames. Style *string `json:"style"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // Specify screenshot type, defaults to `png`. Type *ScreenshotType `json:"type"` }
type PageSelectOptionOptions ¶
type PageSelectOptionOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageSetCheckedOptions ¶
type PageSetCheckedOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageSetContentOptions ¶
type PageSetContentOptions struct { // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type PageSetInputFilesOptions ¶
type PageSetInputFilesOptions struct { // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageTapOptions ¶
type PageTapOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores // current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to // "Control" on Windows and Linux and to "Meta" on macOS. Modifiers []KeyboardModifier `json:"modifiers"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageTextContentOptions ¶
type PageTextContentOptions struct { // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageTypeOptions ¶
type PageTypeOptions struct { // Time to wait between key presses in milliseconds. Defaults to 0. Delay *float64 `json:"delay"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageUncheckOptions ¶
type PageUncheckOptions struct { // Whether to bypass the [actionability] checks. Defaults to `false`. // // [actionability]: https://playwright.dev/docs/actionability Force *bool `json:"force"` // This option has no effect. // // Deprecated: This option has no effect. NoWaitAfter *bool `json:"noWaitAfter"` // A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of // the element. Position *Position `json:"position"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When set, this method only performs the [actionability] checks and skips the action. Defaults // to `false`. Useful to wait until the element is ready for the action without performing it. // // [actionability]: https://playwright.dev/docs/actionability Trial *bool `json:"trial"` }
type PageUnrouteAllOptions ¶ added in v0.4101.0
type PageUnrouteAllOptions struct { // Specifies whether to wait for already running handlers and what to do if they throw errors: // - `default` - do not wait for current handler calls (if any) to finish, if unrouted handler throws, it may // result in unhandled error // - `wait` - wait for current handler calls (if any) to finish // - `ignoreErrors` - do not wait for current handler calls (if any) to finish, all errors thrown by the handlers // after unrouting are silently caught Behavior *UnrouteBehavior `json:"behavior"` }
type PageWaitForEventOptions ¶ added in v0.3500.0
type PageWaitForEventOptions struct { // Receives the event data and resolves to truthy value when the waiting should resolve. Predicate interface{} `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type PageWaitForFunctionOptions ¶
type PageWaitForFunctionOptions struct { // If “polling” is `raf`, then “expression” is constantly executed in `requestAnimationFrame` callback. If “polling” // is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to // `raf`. Polling interface{} `json:"polling"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageWaitForLoadStateOptions ¶
type PageWaitForLoadStateOptions struct { // Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current // document, the method resolves immediately. Can be one of: // - `load` - wait for the `load` event to be fired. // - `domcontentloaded` - wait for the `DOMContentLoaded` event to be fired. // - `networkidle` - **DISCOURAGED** wait until there are no network connections for at least `500` ms. Don't use // this method for testing, rely on web assertions to assess readiness instead. State *LoadState `json:"state"` // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageWaitForSelectorOptions ¶
type PageWaitForSelectorOptions struct { // Defaults to `visible`. Can be either: // - `attached` - wait for element to be present in DOM. // - `detached` - wait for element to not be present in DOM. // - `visible` - wait for element to have non-empty bounding box and no `visibility:hidden`. Note that element // without any content or with `display:none` has an empty bounding box and is not considered visible. // - `hidden` - wait for element to be either detached from DOM, or have an empty bounding box or // `visibility:hidden`. This is opposite to the `visible` option. State *WaitForSelectorState `json:"state"` // When true, the call requires selector to resolve to a single element. If given selector resolves to more than one // element, the call throws an exception. Strict *bool `json:"strict"` // Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` }
type PageWaitForURLOptions ¶
type PageWaitForURLOptions struct { // Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can // be changed by using the [BrowserContext.SetDefaultNavigationTimeout], [BrowserContext.SetDefaultTimeout], // [Page.SetDefaultNavigationTimeout] or [Page.SetDefaultTimeout] methods. Timeout *float64 `json:"timeout"` // When to consider operation succeeded, defaults to `load`. Events can be either: // - `domcontentloaded` - consider operation to be finished when the `DOMContentLoaded` event is fired. // - `load` - consider operation to be finished when the `load` event is fired. // - `networkidle` - **DISCOURAGED** consider operation to be finished when there are no network connections for // at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead. // - `commit` - consider operation to be finished when network response is received and the document started // loading. WaitUntil *WaitUntilState `json:"waitUntil"` }
type Playwright ¶
type Playwright struct { Selectors Selectors Chromium BrowserType Firefox BrowserType WebKit BrowserType Request APIRequest Devices map[string]*DeviceDescriptor // contains filtered or unexported fields }
Playwright represents a Playwright instance
func Run ¶
func Run(options ...*RunOptions) (*Playwright, error)
Run starts a Playwright instance.
Requires the driver and the browsers to be installed before. Either use Install() or use playwright cli.
func (*Playwright) On ¶ added in v0.3500.0
func (c *Playwright) On(name string, handler interface{})
func (*Playwright) Once ¶ added in v0.3500.0
func (c *Playwright) Once(name string, handler interface{})
func (*Playwright) RemoveListener ¶ added in v0.3500.0
func (c *Playwright) RemoveListener(name string, handler interface{})
type PlaywrightAssertions ¶ added in v0.3500.0
type PlaywrightAssertions interface { // Creates a [APIResponseAssertions] object for the given [APIResponse]. // // response: [APIResponse] object to use for assertions. APIResponse(response APIResponse) APIResponseAssertions // Creates a [LocatorAssertions] object for the given [Locator]. // // locator: [Locator] object to use for assertions. Locator(locator Locator) LocatorAssertions // Creates a [PageAssertions] object for the given [Page]. // // page: [Page] object to use for assertions. Page(page Page) PageAssertions }
Playwright gives you Web-First Assertions with convenience methods for creating assertions that will wait and retry until the expected condition is met. Consider the following example: Playwright will be re-testing the node with the selector `.status` until fetched Node has the `"Submitted"` text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is reached. You can pass this timeout as an option. By default, the timeout for assertions is set to 5 seconds.
func NewPlaywrightAssertions ¶ added in v0.3500.0
func NewPlaywrightAssertions(timeout ...float64) PlaywrightAssertions
NewPlaywrightAssertions creates a new instance of PlaywrightAssertions
- timeout: default value is 5000 (ms)
type PlaywrightDriver ¶
type PlaywrightDriver struct { Version string // contains filtered or unexported fields }
func NewDriver ¶
func NewDriver(options *RunOptions) (*PlaywrightDriver, error)
func (*PlaywrightDriver) Command ¶ added in v0.4400.1
func (d *PlaywrightDriver) Command(arg ...string) *exec.Cmd
Command returns an exec.Cmd for the driver.
func (*PlaywrightDriver) DownloadDriver ¶
func (d *PlaywrightDriver) DownloadDriver() error
DownloadDriver downloads the driver only
func (*PlaywrightDriver) Install ¶ added in v0.3800.0
func (d *PlaywrightDriver) Install() error
Install downloads the driver and the browsers depending on RunOptions.
func (*PlaywrightDriver) Uninstall ¶ added in v0.3800.0
func (d *PlaywrightDriver) Uninstall() error
Uninstall removes the driver and the browsers.
type Proxy ¶ added in v0.3500.0
type Proxy struct { // Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example `http://myproxy.com:3128` or // `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy. Server string `json:"server"` // Optional comma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`. Bypass *string `json:"bypass"` // Optional username to use if HTTP proxy requires authentication. Username *string `json:"username"` // Optional password to use if HTTP proxy requires authentication. Password *string `json:"password"` }
type RecordVideo ¶ added in v0.3500.0
type RecordVideo struct { // Path to the directory to put videos into. Dir string `json:"dir"` // Optional dimensions of the recorded videos. If not specified the size will be equal to `viewport` scaled down to // fit into 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450. Actual picture of // each page will be scaled down if necessary to fit the specified size. Size *Size `json:"size"` }
type ReducedMotion ¶
type ReducedMotion string
type Request ¶
type Request interface { // An object with all the request HTTP headers associated with this request. The header names are lower-cased. AllHeaders() (map[string]string, error) // The method returns `null` unless this request has failed, as reported by `requestfailed` event. Failure() error // Returns the [Frame] that initiated this request. // // # Details // // Note that in some cases the frame is not available, and this method will throw. // - When request originates in the Service Worker. You can use `request.serviceWorker()` to check that. // - When navigation request is issued before the corresponding frame is created. You can use // [Request.IsNavigationRequest] to check that. // Here is an example that handles all the cases: Frame() Frame // An object with the request HTTP headers. The header names are lower-cased. Note that this method does not return // security-related headers, including cookie-related ones. You can use [Request.AllHeaders] for complete list of // headers that include `cookie` information. Headers() map[string]string // An array with all the request HTTP headers associated with this request. Unlike [Request.AllHeaders], header names // are NOT lower-cased. Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times. HeadersArray() ([]NameValue, error) // Returns the value of the header matching the name. The name is case-insensitive. // // name: Name of the header. HeaderValue(name string) (string, error) // Some navigation requests are issued before the corresponding frame is created, and therefore do not have // [Request.Frame] available. IsNavigationRequest() bool // Request's method (GET, POST, etc.) Method() string // Request's post body, if any. PostData() (string, error) // Request's post body in a binary form, if any. PostDataBuffer() ([]byte, error) // Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any. // When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned. // Otherwise it will be parsed as JSON. PostDataJSON(v interface{}) error // Request that was redirected by the server to this one, if any. // When the server responds with a redirect, Playwright creates a new [Request] object. The two requests are connected // by `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to // construct the whole redirect chain by repeatedly calling `redirectedFrom()`. RedirectedFrom() Request // New request issued by the browser if the server responded with redirect. RedirectedTo() Request // Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the // following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, // `eventsource`, `websocket`, `manifest`, `other`. ResourceType() string // Returns the matching [Response] object, or `null` if the response was not received due to error. Response() (Response, error) // Returns resource size information for given request. Sizes() (*RequestSizesResult, error) // Returns resource timing information for given request. Most of the timing values become available upon the // response, `responseEnd` becomes available when request finishes. Find more information at // [Resource Timing API]. // // [Resource Timing API]: https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming Timing() *RequestTiming // URL of the request. URL() string }
Whenever the page sends a request for a network resource the following sequence of events are emitted by Page:
- [Page.OnRequest] emitted when the request is issued by the page.
- [Page.OnResponse] emitted when/if the response status and headers are received for the request.
- [Page.OnRequestFinished] emitted when the response body is downloaded and the request is complete.
If request fails at some point, then instead of `requestfinished` event (and possibly instead of 'response' event), the [Page.OnRequestFailed] event is emitted. **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with `requestfinished` event. If request gets a 'redirect' response, the request is successfully finished with the `requestfinished` event, and a new request is issued to a redirected url.
type RequestSizesResult ¶
type RequestSizesResult struct { // Size of the request body (POST data payload) in bytes. Set to 0 if there was no body. RequestBodySize int `json:"requestBodySize"` // Total number of bytes from the start of the HTTP request message until (and including) the double CRLF before the // body. RequestHeadersSize int `json:"requestHeadersSize"` // Size of the received response body (encoded) in bytes. ResponseBodySize int `json:"responseBodySize"` // Total number of bytes from the start of the HTTP response message until (and including) the double CRLF before the // body. ResponseHeadersSize int `json:"responseHeadersSize"` }
type RequestTiming ¶ added in v0.3700.0
type RequestTiming struct { // Request start time in milliseconds elapsed since January 1, 1970 00:00:00 UTC StartTime float64 `json:"startTime"` // Time immediately before the browser starts the domain name lookup for the resource. The value is given in // milliseconds relative to `startTime`, -1 if not available. DomainLookupStart float64 `json:"domainLookupStart"` // Time immediately after the browser starts the domain name lookup for the resource. The value is given in // milliseconds relative to `startTime`, -1 if not available. DomainLookupEnd float64 `json:"domainLookupEnd"` // Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. // The value is given in milliseconds relative to `startTime`, -1 if not available. ConnectStart float64 `json:"connectStart"` // Time immediately before the browser starts the handshake process to secure the current connection. The value is // given in milliseconds relative to `startTime`, -1 if not available. SecureConnectionStart float64 `json:"secureConnectionStart"` // Time immediately before the user agent starts establishing the connection to the server to retrieve the resource. // The value is given in milliseconds relative to `startTime`, -1 if not available. ConnectEnd float64 `json:"connectEnd"` // Time immediately before the browser starts requesting the resource from the server, cache, or local resource. The // value is given in milliseconds relative to `startTime`, -1 if not available. RequestStart float64 `json:"requestStart"` // Time immediately after the browser receives the first byte of the response from the server, cache, or local // resource. The value is given in milliseconds relative to `startTime`, -1 if not available. ResponseStart float64 `json:"responseStart"` // Time immediately after the browser receives the last byte of the resource or immediately before the transport // connection is closed, whichever comes first. The value is given in milliseconds relative to `startTime`, -1 if not // available. ResponseEnd float64 `json:"responseEnd"` }
type Response ¶
type Response interface { // An object with all the response HTTP headers associated with this response. AllHeaders() (map[string]string, error) // Returns the buffer with response body. Body() ([]byte, error) // Waits for this response to finish, returns always `null`. Finished() error // Returns the [Frame] that initiated this response. Frame() Frame // Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via // [FetchEvent.RespondWith]. // // [FetchEvent.RespondWith]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith) FromServiceWorker() bool // An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return // security-related headers, including cookie-related ones. You can use [Response.AllHeaders] for complete list of // headers that include `cookie` information. Headers() map[string]string // An array with all the request HTTP headers associated with this response. Unlike [Response.AllHeaders], header // names are NOT lower-cased. Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times. HeadersArray() ([]NameValue, error) // Returns the value of the header matching the name. The name is case-insensitive. If multiple headers have the same // name (except `set-cookie`), they are returned as a list separated by `, `. For `set-cookie`, the `\n` separator is // used. If no headers are found, `null` is returned. // // name: Name of the header. HeaderValue(name string) (string, error) // Returns all values of the headers matching the name, for example `set-cookie`. The name is case-insensitive. // // name: Name of the header. HeaderValues(name string) ([]string, error) // Returns the JSON representation of response body. // This method will throw if the response body is not parsable via `JSON.parse`. JSON(v interface{}) error // Contains a boolean stating whether the response was successful (status in the range 200-299) or not. Ok() bool // Returns the matching [Request] object. Request() Request // Returns SSL and other security information. SecurityDetails() (*ResponseSecurityDetailsResult, error) // Returns the IP address and port of the server. ServerAddr() (*ResponseServerAddrResult, error) // Contains the status code of the response (e.g., 200 for a success). Status() int // Contains the status text of the response (e.g. usually an "OK" for a success). StatusText() string // Returns the text representation of response body. Text() (string, error) // Contains the URL of the response. URL() string }
Response class represents responses which are received by page.
type ResponseSecurityDetailsResult ¶
type ResponseSecurityDetailsResult struct { // Common Name component of the Issuer field. from the certificate. This should only be used for informational // purposes. Optional. Issuer *string `json:"issuer"` // The specific TLS protocol used. (e.g. `TLS 1.3`). Optional. Protocol *string `json:"protocol"` // Common Name component of the Subject field from the certificate. This should only be used for informational // purposes. Optional. SubjectName *string `json:"subjectName"` // Unix timestamp (in seconds) specifying when this cert becomes valid. Optional. ValidFrom *float64 `json:"validFrom"` // Unix timestamp (in seconds) specifying when this cert becomes invalid. Optional. ValidTo *float64 `json:"validTo"` }
type Route ¶
type Route interface { // Aborts the route's request. Abort(errorCode ...string) error // Sends route's request to the network with optional overrides. // // # Details // // Note that any overrides such as “url” or “headers” only apply to the request being routed. If this request results // in a redirect, overrides will not be applied to the new redirected request. If you want to propagate a header // through redirects, use the combination of [Route.Fetch] and [Route.Fulfill] instead. // [Route.Continue] will immediately send the request to the network, other matching handlers won't be invoked. Use // [Route.Fallback] If you want next matching handler in the chain to be invoked. Continue(options ...RouteContinueOptions) error // Continues route's request with optional overrides. The method is similar to [Route.Continue] with the difference // that other matching handlers will be invoked before sending the request. Fallback(options ...RouteFallbackOptions) error // Performs the request and fetches result without fulfilling it, so that the response could be modified and then // fulfilled. // // # Details // // Note that “headers” option will apply to the fetched request as well as any redirects initiated by it. If you want // to only apply “headers” to the original request, but not to redirects, look into [Route.Continue] instead. Fetch(options ...RouteFetchOptions) (APIResponse, error) // Fulfills route's request with given response. Fulfill(options ...RouteFulfillOptions) error // A request to be routed. Request() Request }
Whenever a network route is set up with [Page.Route] or [BrowserContext.Route], the `Route` object allows to handle the route. Learn more about networking.
type RouteContinueOptions ¶
type RouteContinueOptions struct { // If set changes the request HTTP headers. Header values will be converted to a string. Headers map[string]string `json:"headers"` // If set changes the request method (e.g. GET or POST). Method *string `json:"method"` // If set changes the post data of request. PostData interface{} `json:"postData"` // If set changes the request URL. New URL must have same protocol as original one. URL *string `json:"url"` }
type RouteFallbackOptions ¶ added in v0.3500.0
type RouteFallbackOptions struct { // If set changes the request HTTP headers. Header values will be converted to a string. Headers map[string]string `json:"headers"` // If set changes the request method (e.g. GET or POST). Method *string `json:"method"` // If set changes the post data of request. PostData interface{} `json:"postData"` // If set changes the request URL. New URL must have same protocol as original one. Changing the URL won't affect the // route matching, all the routes are matched using the original request URL. URL *string `json:"url"` }
type RouteFetchOptions ¶ added in v0.3500.0
type RouteFetchOptions struct { // If set changes the request HTTP headers. Header values will be converted to a string. Headers map[string]string `json:"headers"` // Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is // exceeded. Defaults to `20`. Pass `0` to not follow redirects. MaxRedirects *int `json:"maxRedirects"` // Maximum number of times network errors should be retried. Currently only `ECONNRESET` error is retried. Does not // retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to `0` - no retries. MaxRetries *int `json:"maxRetries"` // If set changes the request method (e.g. GET or POST). Method *string `json:"method"` // If set changes the post data of request. PostData interface{} `json:"postData"` // Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Timeout *float64 `json:"timeout"` // If set changes the request URL. New URL must have same protocol as original one. URL *string `json:"url"` }
type RouteFromHarUpdateContentPolicy ¶ added in v0.3500.0
type RouteFromHarUpdateContentPolicy string
var ( RouteFromHarUpdateContentPolicyEmbed *RouteFromHarUpdateContentPolicy = getRouteFromHarUpdateContentPolicy("embed") RouteFromHarUpdateContentPolicyAttach = getRouteFromHarUpdateContentPolicy("attach") )
type RouteFulfillOptions ¶
type RouteFulfillOptions struct { // Response body. Body interface{} `json:"body"` // If set, equals to setting `Content-Type` response header. ContentType *string `json:"contentType"` // Response headers. Header values will be converted to a string. Headers map[string]string `json:"headers"` // File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, // then it is resolved relative to the current working directory. Path *string `json:"path"` // [APIResponse] to fulfill route's request with. Individual fields of the response (such as headers) can be // overridden using fulfill options. Response APIResponse `json:"response"` // Response status code, defaults to `200`. Status *int `json:"status"` }
type RunOptions ¶
type RunOptions struct { DriverDirectory string SkipInstallBrowsers bool Browsers []string Verbose bool // default true Stdout io.Writer Stderr io.Writer }
RunOptions are custom options to run the driver
type SameSiteAttribute ¶
type SameSiteAttribute string
type ScreenshotAnimations ¶
type ScreenshotAnimations string
var ( ScreenshotAnimationsDisabled *ScreenshotAnimations = getScreenshotAnimations("disabled") ScreenshotAnimationsAllow = getScreenshotAnimations("allow") )
type ScreenshotCaret ¶ added in v0.3500.0
type ScreenshotCaret string
var ( ScreenshotCaretHide *ScreenshotCaret = getScreenshotCaret("hide") ScreenshotCaretInitial = getScreenshotCaret("initial") )
type ScreenshotScale ¶ added in v0.3500.0
type ScreenshotScale string
var ( ScreenshotScaleCss *ScreenshotScale = getScreenshotScale("css") ScreenshotScaleDevice = getScreenshotScale("device") )
type ScreenshotType ¶
type ScreenshotType string
var ( ScreenshotTypePng *ScreenshotType = getScreenshotType("png") ScreenshotTypeJpeg = getScreenshotType("jpeg") )
type SelectOptionValues ¶
type SelectOptionValues struct { ValuesOrLabels *[]string Values *[]string Indexes *[]int Labels *[]string Elements *[]ElementHandle }
SelectOptionValues is the option struct for ElementHandle.Select() etc.
type Selectors ¶ added in v0.3500.0
type Selectors interface { // Selectors must be registered before creating the page. // // 1. name: Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only // contain `[a-zA-Z0-9_]` characters. // 2. script: Script that evaluates to a selector engine instance. The script is evaluated in the page context. Register(name string, script Script, options ...SelectorsRegisterOptions) error // Defines custom attribute name to be used in [Page.GetByTestId]. `data-testid` is used by default. // // attributeName: Test id attribute name. SetTestIdAttribute(attributeName string) }
Selectors can be used to install custom selector engines. See extensibility for more information.
type SelectorsRegisterOptions ¶
type SelectorsRegisterOptions struct { // Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same // DOM, but not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content // script is not guaranteed when this engine is used together with other registered engines. ContentScript *bool `json:"contentScript"` }
type ServiceWorkerPolicy ¶ added in v0.3500.0
type ServiceWorkerPolicy string
var ( ServiceWorkerPolicyAllow *ServiceWorkerPolicy = getServiceWorkerPolicy("allow") ServiceWorkerPolicyBlock = getServiceWorkerPolicy("block") )
type StorageState ¶
func (StorageState) ToOptionalStorageState ¶ added in v0.4102.0
func (s StorageState) ToOptionalStorageState() *OptionalStorageState
ToOptionalStorageState converts StorageState to OptionalStorageState for use directly in [Browser.NewContext]
type Touchscreen ¶
type Touchscreen interface { // Dispatches a `touchstart` and `touchend` event with a single touch at the position (“x”,“y”). // **NOTE** [Page.Tap] the method will throw if “hasTouch” option of the browser context is false. // // 1. x: X coordinate relative to the main frame's viewport in CSS pixels. // 2. y: Y coordinate relative to the main frame's viewport in CSS pixels. Tap(x int, y int) error }
The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the touchscreen can only be used in browser contexts that have been initialized with `hasTouch` set to true.
type Tracing ¶
type Tracing interface { // Start tracing. Start(options ...TracingStartOptions) error // Start a new trace chunk. If you'd like to record multiple traces on the same [BrowserContext], use [Tracing.Start] // once, and then create multiple trace chunks with [Tracing.StartChunk] and [Tracing.StopChunk]. StartChunk(options ...TracingStartChunkOptions) error // Stop tracing. Stop(path ...string) error // Stop the trace chunk. See [Tracing.StartChunk] for more details about multiple trace chunks. StopChunk(path ...string) error }
API for collecting and saving Playwright traces. Playwright traces can be opened in Trace Viewer after Playwright script runs. Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
type TracingStartChunkOptions ¶
type TracingStartChunkOptions struct { // If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the // “tracesDir” folder specified in [BrowserType.Launch]. To specify the final trace zip file name, you need to pass // `path` option to [Tracing.StopChunk] instead. Name *string `json:"name"` // Trace name to be shown in the Trace Viewer. Title *string `json:"title"` }
type TracingStartOptions ¶
type TracingStartOptions struct { // If specified, intermediate trace files are going to be saved into the files with the given name prefix inside the // “tracesDir” folder specified in [BrowserType.Launch]. To specify the final trace zip file name, you need to pass // `path` option to [Tracing.Stop] instead. Name *string `json:"name"` // Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview. Screenshots *bool `json:"screenshots"` // If this option is true tracing will // - capture DOM snapshot on every action // - record network activity Snapshots *bool `json:"snapshots"` // Whether to include source files for trace actions. Sources *bool `json:"sources"` // Trace name to be shown in the Trace Viewer. Title *string `json:"title"` }
type UnrouteBehavior ¶ added in v0.4101.0
type UnrouteBehavior string
type Video ¶
type Video interface { // Deletes the video file. Will wait for the video to finish if necessary. Delete() error // Returns the file system path this video will be recorded to. The video is guaranteed to be written to the // filesystem upon closing the browser context. This method throws when connected remotely. Path() (string, error) // Saves the video to a user-specified path. It is safe to call this method while the video is still in progress, or // after the page has closed. This method waits until the page is closed and the video is fully saved. // // path: Path where the video should be saved. SaveAs(path string) error }
When browser context is created with the `recordVideo` option, each page has a video object associated with it.
type WaitForSelectorState ¶
type WaitForSelectorState string
type WaitUntilState ¶
type WaitUntilState string
type WebError ¶ added in v0.3800.0
type WebError interface { // The page that produced this unhandled exception, if any. Page() Page // Unhandled error that was thrown. Error() error }
WebError class represents an unhandled exception thrown in the page. It is dispatched via the [BrowserContext.OnWebError] event.
type WebSocket ¶
type WebSocket interface { // Fired when the websocket closes. OnClose(fn func(WebSocket)) // Fired when the websocket receives a frame. OnFrameReceived(fn func([]byte)) // Fired when the websocket sends a frame. OnFrameSent(fn func([]byte)) // Fired when the websocket has an error. OnSocketError(fn func(string)) // Indicates that the web socket has been closed. IsClosed() bool // Contains the URL of the WebSocket. URL() string // Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy // value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value. // // event: Event name, same one would pass into `webSocket.on(event)`. ExpectEvent(event string, cb func() error, options ...WebSocketExpectEventOptions) (interface{}, error) // **NOTE** In most cases, you should use [WebSocket.ExpectEvent]. // Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function // and waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the // `event` is fired. // // event: Event name, same one typically passed into `*.on(event)`. WaitForEvent(event string, options ...WebSocketWaitForEventOptions) (interface{}, error) }
The WebSocket class represents websocket connections in the page.
type WebSocketExpectEventOptions ¶ added in v0.3500.0
type WebSocketExpectEventOptions struct { // Receives the event data and resolves to truthy value when the waiting should resolve. Predicate interface{} `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type WebSocketWaitForEventOptions ¶ added in v0.3500.0
type WebSocketWaitForEventOptions struct { // Receives the event data and resolves to truthy value when the waiting should resolve. Predicate interface{} `json:"predicate"` // Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The // default value can be changed by using the [BrowserContext.SetDefaultTimeout]. Timeout *float64 `json:"timeout"` }
type Worker ¶
type Worker interface { // Emitted when this dedicated [WebWorker] is // terminated. // // [WebWorker]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API OnClose(fn func(Worker)) // Returns the return value of “expression”. // If the function passed to the [Worker.Evaluate] returns a [Promise], then [Worker.Evaluate] would wait for the // promise to resolve and return its value. // If the function passed to the [Worker.Evaluate] returns a non-[Serializable] value, then [Worker.Evaluate] returns // `undefined`. Playwright also supports transferring some additional values that are not serializable by `JSON`: // `-0`, `NaN`, `Infinity`, `-Infinity`. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. Evaluate(expression string, arg ...interface{}) (interface{}, error) // Returns the return value of “expression” as a [JSHandle]. // The only difference between [Worker.Evaluate] and [Worker.EvaluateHandle] is that [Worker.EvaluateHandle] returns // [JSHandle]. // If the function passed to the [Worker.EvaluateHandle] returns a [Promise], then [Worker.EvaluateHandle] would wait // for the promise to resolve and return its value. // // 1. expression: JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the // function is automatically invoked. // 2. arg: Optional argument to pass to “expression”. EvaluateHandle(expression string, arg ...interface{}) (JSHandle, error) URL() string }
The Worker class represents a WebWorker. `worker` event is emitted on the page object to signal a worker creation. `close` event is emitted on the worker object when the worker is gone.
Source Files ¶
- apiresponse_assertions.go
- artifact.go
- assertions.go
- binding_call.go
- browser.go
- browser_context.go
- browser_type.go
- cdp_session.go
- channel.go
- channel_owner.go
- clock.go
- connection.go
- console_message.go
- dialog.go
- download.go
- element_handle.go
- errors.go
- event_emitter.go
- fetch.go
- file_chooser.go
- frame.go
- frame_locator.go
- generated-enums.go
- generated-interfaces.go
- generated-structs.go
- glob.go
- har_router.go
- helpers.go
- input.go
- input_files_helper.go
- js_handle.go
- jsonPipe.go
- local_utils.go
- locator.go
- locator_assertions.go
- locator_helpers.go
- network.go
- objectFactory.go
- page.go
- page_assertions.go
- playwright.go
- request.go
- response.go
- route.go
- run.go
- run_unix.go
- selectors.go
- stream.go
- tracing.go
- transport.go
- type_helpers.go
- video.go
- waiter.go
- web_error.go
- websocket.go
- worker.go
- writable_stream.go