Playwright synchronization module sync_API Create Page

Create a page (tab) in the context.

Page; Context.new_Page().

Methods and properties of the page.

The events supported by the page page.

"Close", "console" (when JavaScript calls the console API), "crash" (when the page crashes), "dialog" (when a dialog box appears, all dialog boxes are closed by default), "domcontentloaded", "download" (when the download starts), "fileselector" (when the file selector appears), "frameattached" (when joining the framework), "framedetached" (when uninstalling the framework), "framenavigated" (when navigating the framework to a new URL) "Load" (page loading completed), "pageerror" (when an uncaught exception occurs on the page), "pop" (when opening a new tab or window), "request" (when the page makes a request), "requestfailed" (when the request fails), "requestfinished" (when the request is successfully completed after downloading the response body), "response" (when receiving the response status and header of the request), "websocket" (when sending a WebSocket request) "Worker" (when generating a dedicated WebWorker).

Page properties:
Keyboard: Page Keyboard Object Mouse: Page Mouse Object Context: Get the browser context to which the page belongs
Frames: Get a list of all frames on the page
Main_Frame: Get the main frame of the page
URL: The URL of the page
Video: The video object associated with this page
Requests: Request API.

Add_Init_Script( After creating the document, but before running any of its scripts, run the specified JavaScript script
Add_Script_Tag(
Content, path, style, URL): Inject the JS code specified by content and the JS file specified by path into the framework specified by URL, with a style of" Module" Indicates ES6
Add_Style_Tag (* *, content, path, URL): Inject the specified CSS style
Bring_To_Front(): Place the page at the front (activate tab).

Check (selector, , force, no_Wait_After, position, timeout: Find and select the radio or checkbox found
Uncheck (selector,
, force, no_Wait_After, position, timeout: Find and deselect the radio or checkbox found
Click (selector, , button, click_Count, delay, force, modifiers, position, timeout, no_Wait_After
Dblclick (selector
Button, delay, force, modifiers, position, timeout, no_Wait_After
Selector: str, CSS selector syntax for finding elements, supports pseudo classes, if multiple elements are found, the first
will be used Modifiers: list (None), the key that is held down during operation, and the supported elements in the list are 'Alt', 'Control', 'Meta', 'Shift'
Position: tuple, specify the coordinates relative to the top left corner of the element as the click position, if not specified, use a visible point of the element
Delay: int, the interval time between mouse press and release (milliseconds)
Button: str, which mouse button is pressed, supports' left ',' middle ',' right '
Click_Count: int (1), number of clicks
Timeout: int (30000), the timeout for completing the operation. If the specified element is not found, it will wait until the element is found.
Force: bool (False), whether to bypass operability check
No_Wait_After: bool (False), do you want to not wait for the page to load Strict: bool, if true, requires the selector to resolve to a single element. If the selector resolves to multiple elements, an exception will be thrown
Close (run_before_unload): Close the page, run_Before_"Unload" indicates whether to run the pre uninstallation page processing program. The default is False
Content(): Get the complete HTML content of the page, including doctype
Dispatch_Event (selector, event, (timeout): Runs the specified event of the specified element (regardless of whether the element is visible)
Drag_And_Drop (source, target, Kwargs: element drag and drop operation
Source: str
Target: str
Force: bool (Fasle), whether to bypass operability check
No_Wait_After: bool (Fasle), do you want to skip waiting for loading content?
Source_Position: dict, the click position of the inspiration element {x: float; y: float}
Target_Position: dict, the click position of the terminating element {x: float; y: float}
Timeout: float (30000), timeout (milliseconds)
Eval_On_Selector (selector, expression, arg)
Expression: str, it appears that the function is interpreted as a function (the first parameter is the selected element), otherwise it is interpreted as an expression
Arg is the other parameter passed to the function
If the expression returns a Promise, it will wait for the Promise to resolve and return its value
Eval_On_Selector_All (selector, expression, arg)
Find all matching elements (arrays) on the page and pass the array as the first parameter to the function
Evaluate (expression, arg): JavaScript code for running expression string parsing
Expect_Event (event: str,
, predict: fun= None, timeout: float= 30000.0)
Wait for the specified event to occur and execute the predict specified method, while the fun method accepts the specified event data
This method returns a context manager
Expect_Navigation(
, timeout, wait_Until: Wait for the main framework to load before returning the corresponding resources
Wait_Until: specifies the flag for loading completion
'domcontentloaded ': When the DOMContentLoaded event is triggered
'load': When the load event is triggered, it defaults to load
'networkidle': When there is no network connection for at least 500 milliseconds
'commit': When receiving a network response and starting to load the document
Expose_Binding (name, callback, (handle: bool): Bind a function to the page
Name: Binding Function Name
Callback: Bind the function to be executed, which takes an object containing all the information on the current page
Handle: Whether to pass parameters as handles instead of values. When passing a handle, only one parameter is supported. When passing by value, supports multiple parameters
Expose_Function (name: str, callback: fun): The function is the same as before, but this method does not automatically pass parameters
Fill (selector, value, Kwargs:
Perform a series of operations: find specified elements, perform operability checks, focus on elements, and fill in specified content
The found elements can only be input, textarea, or elements with the contenteditable attribute set, otherwise an error will be reported
Optional parameters for kwargs: force, timeout, no_Wait_After
Focus (selector,
(timeout): Find the specified element and focus it
Page.frame(
(name, URL): Find and return the specified frame on the page
Name is the name attribute value of the framework
Urls can use global pattern strings or regular objects
Get_Attribute (selector, name, (timeout): Get the name attribute value of the element
Go_Back(
, timeout, wait_Until: Step back in history
Go_Forward (timeout, wait_until): Take one step forward in history
Goto (URL, , timeout, wait_Until, referer: Visit the specified website
Hover (selector,
(modifiers, position, timeout, force): Find an element and move the cursor over it
Inner_HTML (selector, (timeout): returns the element. inerHTML of the specified element
Inner_Text (selector,
(timeout): returns the element. inerText of the specified element
Input_Value (selector, (timeout): Returns the value value of a specified input, textarea, or select element
Is_Checked (selector,
(timeout): Check if the element is checked or single selected
Is_Disabled (selector, (timeout): Check if the element is disabled
Is_Editable (selector,
(timeout): Check if the element is editable
Is_Enabled (selector, (timeout): Check if the element is enabled
Is_Hidden (selector,
(timeout): Check if the element is invisible
Is_Visible (selector, (timeout): Check if the element is visible
Is_Enabled (selector,
(timeout): Check if the element is enabled
Is_Enabled (selector, (timeout): Check if the element is enabled
Is_Closed(): Check if the page is closed
Locator (selector): returns the specified element
Opener(): returns to the parent page, and if it is closed or does not exist, returns null
Pause(): pauses the execution of the script
PDF( Kwargs: Save the page as a PDF file
Display_Header_Footer: bool (False), whether to display header and footer
Height, width: str | float, paper height and width
Can accept strings containing units, accepted units include px (pixels), in (inches), cm (centimeters), mm (millimeters)
Float is measured in pixels
Landscape: bool (False), whether to display in wide format
Margin: dict, inner margin, available in four fields: top, right, bottom, and left, with values of float or str
Page_Ranges: str, printing range, such as" 2-4,7,9-11", Default empty string, indicating printing all pages
Path: str, save path for PDF
Scale: float, the display size of the page, accepts floating-point numbers ranging from 0.1 to 2
Press (selector, key, , delay, no_Wait_After, timeout: Focus on the specified element, press the specified button and release
Delay: float (0.0), time interval between pressing and releasing (milliseconds)
Key: str, available values include: F1-F12, Digit0 Digit9, KeyA KeyZ, Backquote, Minus, Equal, Backflash, Backspace, Tab, Delete, Escape, ArrowDown, End, Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp, Shift, Control, Alt, Meta, ShiftLeft
Combination can be used, such as" Control; O" Or; Control; Shift; T", Using combinations of letters to directly use characters
Query_Selector (selector): Find the first matching element on the page and return it, return ElementHandle
Query_Selector_All (selector): Find all matching elements on the page and return a list
Reload(
, timeout, wait_Until: Reload page
Screenshot(
, clip, full_Page, omit_Background, path, quality, timeout, type): Screenshot
Clip: dict, specify the area to be truncated, available fields
x. Y: float, starting coordinates of truncation
Width, height: float, the width and height of the truncated area
Full_Page: bool (False), whether to capture all page content containing scrolling, default to only capturing visible areas
Omit_Background: bool (False), is the background transparent Quality: int, saving image quality from 0 to 100, only applicable to jpeg format
Type: str ("jpeg"), specify image type, optional" Jpeg; Or; Png"< Br> Set_Checked (selector, checked, Kwargs: Select radio or check to operate
Checked: bool, is this element in a selected or unselected state?
Force: bool (False), is enough to bypass operability checks
Position: dict, the coordinates of the element to be clicked relative to the top left corner (float fields x and y)
No_Wait_After, timeout
Uncheck (selector, Kwargs: Set the specified single or multiple selection to the unselected state, with optional parameters such as force, position, and no_Wait_After, timeout
Set_Content (HTML,
, timeout, wait_Until: Fill the page with the specified HTML code string
Set_Default_Navigation_Timeout: Set the default page loading timeout time
Set_Default_Timeout: Set the default timeout time
Set_Extra_HTTP_Headers (dict): Each request initiated by the page will send an additional HTTP header
Set_Input_Files (selector, files, Kwargs
Select the specified input element and enter the path to the specified file
Files: str, [str] list or dict, available fields for dict
Name: str, file name
MimeType: str, file type
Buffer: bytes, the content of the file
Set_Viewport_Size (dict): Set the view size of the page, width and height fields of type int, in pixels
Text_Content (selector,
, timeout): returns element. textContent
Title(): Return to page title
Type (selector, text, , delay, no_Wait_After, timeout): Focuses on the specified element without sending keydown and keypress events for each character in the text
Viewport_Size(): The size of the page window
Wait_For_Event,
, predict, timeout)
Wait for the event to trigger and pass its value to the predict function
It will also be passed to page. on (event)
Wait_For_Function (expression,
, arg, polling, timeout): Continuously running expression expressions
Polling: float, time interval between running expressions (in milliseconds)
Wait_For_Load_State(
(state, timeout): Wait until the specified page loading state
State: str ("load"): optional values' load ',' domcontentloaded ',' networkidle '(no network connection for at least 500 milliseconds)
Wait_For_Selector (selector, * *, state, timeout): returns a modified element when the specified element meets the condition
State: str ("visible"), available values
'attached': Wait for the element to appear in the DOM
'detached ': The waiting element does not exist in the DOM
'visible': Wait for the element to have a non empty bounding box and not hidden. No content or boundaries are considered hidden
'hidden': Wait for elements to separate from DOM, or have empty bounding boxes or hide