Extends
Methods
(async) $(selector) → {Promise.<?ElementHandle>}
The method runs
document.querySelector()
within the
page.
If no element matches the selector, the
return value resolve to null
.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string |
A selector to query page for |
Returns:
- Type
- Promise.<?ElementHandle>
(async) $$(selector) → {Promise.<Array.<ElementHandle>>}
The method runs
document.querySelectorAll()
within the
page.
If no elements match the selector, the
return value resolve to [ ]
.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string |
A selector to query page for |
Returns:
- Type
- Promise.<Array.<ElementHandle>>
$$eval(selector, runInPage, …parameter) → {Promise.<Serializable>}
This method runs
Array.from(document.querySelectorAll(selector))
within the page
and passes it as the first
argument to runInPage
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selector |
String |
A selector to query page for |
|
runInPage |
function |
Function to be evaluated in browser context |
|
parameter |
Serializable |
<repeatable> |
Arguments to pass to
|
Returns:
Promise which resolves to the return value of
runInPage
- Type
- Promise.<Serializable>
$eval(selector, runInPage, …parameter) → {Promise.<Serializable>}
This method runs
document.querySelector()
within the
page
and passes it as the first argument to
runInPage
.
If there's no element
matching selector, the method throws an error.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selector |
String |
A selector to query page for |
|
runInPage |
function |
Function to be evaluated in browser context |
|
parameter |
Serializable |
<repeatable> |
Arguments to pass to
|
Returns:
Promise which resolves to the return value of
runInPage
- Type
- Promise.<Serializable>
(async) addScriptTag(options) → {Promise.<ElementHandle>}
Adds a <script>
tag into the page
with the desired url or content
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
Returns:
which resolves to the added tag when the script's
onload fires
or when the script content was injected into frame
- Type
- Promise.<ElementHandle>
(async) addStyleTag(options) → {Promise.<ElementHandle>}
Adds a
<link rel="stylesheet">
tag into the page with the desired url
or a
<style type="text/css">
tag with the content
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
Returns:
which resolves to the added tag when the
stylesheet's onload fires
or when the CSS content was injected into frame
- Type
- Promise.<ElementHandle>
(async) click(selector, optionsopt) → {Promise}
This method fetches an element with selector,
scrolls it into view if needed,
and then uses
page.mouse
to click in the center of
the element.
If there's no element matching
selector, the method throws an error.
Bare in mind that if .click()
triggers
a navigation event
and there's a separate
page.waitForNavigation()
promise to be
resolved,
you may end up with a race condition
that yields unexpected results.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
selector |
string |
A selector to search for element to
click. |
|||||||||||||||||||||
options |
object | <optional> |
Properties
|
Returns:
Promise which resolves when the element matching
selector is successfully clicked.
The Promise will be rejected if there is no element
matching selector.
- Type
- Promise
(async) close()
Fires:
- Page#event:close
(async) content() → {Promise.<string>}
Gets the full HTML contents of the page, including the doctype.
Returns:
- Type
- Promise.<string>
cookies(…urls) → {Promise.<Array.<Object>>}
If no URLs are specified, this method returns
cookies for the current page URL.
If URLs are
specified, only cookies for those URLs are returned.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
urls |
string |
<repeatable> |
Returns:
Include keys of name
,
value
, domain
,
path
,
expires
, httpOnly
,
secure
, session
&
sameSite
.
- Type
- Promise.<Array.<Object>>
deleteCookie(…cookies) → {Promise}
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cookies |
object |
<repeatable> |
Properties
|
Returns:
- Type
- Promise
evaluate(expression, …parameter) → {Promise.<Serializable>}
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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
expression |
function | string |
Function or Expression to be evaluated in the page context |
|
parameter |
Serializable |
<repeatable> |
Arguments to pass to the function |
Returns:
Promise which resolves to the value of
expression
- Type
- Promise.<Serializable>
(async) evaluateHandle(expression, …parameter) → {Promise.<ElementHandle>}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
expression |
function | string |
Function or Expression to be evaluated in the page context |
|
parameter |
Serializable |
<repeatable> |
Arguments to pass to the function |
Returns:
Promise which resolves to the value of
expression
as
in-page Element
- Type
- Promise.<ElementHandle>
(async) exposeFunction(name, puppeteerFunction) → {Promise}
The method adds a function called
name
on the page's window object.
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
Name of the function on the
|
puppeteerFunction
|
function |
Callback function which will be called
in Puppeteer's context, |
Returns:
Promise which resolves to the return value of
puppeteerFunction
- Type
- Promise
(async) focus(selector) → {Promise}
This method fetches an element with selector and
focuses it.
If there's no element matching
selector, the method throws an error.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string |
A selector of an element to focus. |
Returns:
Promise which resolves when the element matching
selector is successfully focused.
The promise will be rejected if there is no element
matching selector.
- Type
- Promise
goBack(optionsopt) → {Promise}
Navigate to the previous page in history
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | <optional> |
Properties
|
Returns:
- Type
- Promise
goForward(optionsopt) → {Promise}
Navigate to the next page in history
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | <optional> |
Properties
|
Returns:
- Type
- Promise
goto(urlopt, optionsopt) → {Promise}
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
string | <optional> |
'about:blank'
|
URL to navigate page to. |
|||||||||||||||
options |
object | <optional> |
Properties
|
Returns:
- Type
- Promise
(async) hover(selector) → {Promise}
This method fetches an element with selector,
scrolls it into view if needed,
and then uses
page.mouse to hover over the center of the element.
If there's no element matching selector, the method throws an error.
Parameters:
Name | Type | Description |
---|---|---|
selector |
string |
A selector to search for element to
hover. |
Returns:
Promise which resolves when the element matching
selector is successfully hovered.
Promise gets rejected if there's no element matching
selector.
- Type
- Promise
reload(optionsopt) → {Promise}
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | <optional> |
Properties
|
Returns:
- Type
- Promise
(async) screenshot(optionsopt) → {Promise.<Buffer>}
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | <optional> |
Properties
|
Returns:
Promise which resolves to buffer with captured screenshot
(async) select(selector, …values) → {Promise.<Array.<string>>}
Triggers a change
and
input
event once all the provided
options have been selected.
If there's no
<select>
element matching
selector, the method throws an error.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selector |
string |
A selector to query page for |
|
values |
string |
<repeatable> |
Values of options to select. |
Returns:
Returns an array of option values
that have been successfully selected
- Type
- Promise.<Array.<string>>
(async) setContent(HTML)
Parameters:
Name | Type | Description |
---|---|---|
HTML |
string |
HTML markup to assign to the page |
setCookie(…cookies) → {Promise}
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
cookies |
object |
<repeatable> |
Properties
|
Returns:
- Type
- Promise
setViewport(viewport) → {Promise}
In the case of multiple pages in a single
browser,
each page can have its own viewport
size.
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
viewport |
object |
Properties
|
Returns:
- Type
- Promise
(async) title() → {Promise.<string>}
Returns:
- Type
- Promise.<string>
(async) type(selector, text, optionsopt) → {Promise}
Sends a keydown
,
keypress
/input
, and
keyup
event
for each character in
the text.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
selector |
string |
A selector of an element to type
into. |
|||||||||||
text |
string |
A text to type into a focused element |
|||||||||||
options |
object | <optional> |
Properties
|
Returns:
- Type
- Promise
url() → {string}
Returns:
- Type
- string
(async) viewport() → {Promise.<object>}
Returns:
Include keys of width
,
height
,
deviceScaleFactor
,
isMobile
, hasTouch
&
isLandscape
- Type
- Promise.<object>
waitFor(condition, optionsnullable, …parameteropt) → {Promise}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
condition |
number | string | function |
A selector, predicate or timeout to wait for |
|
options |
object | <nullable> |
|
parameter |
Serializable |
<optional> <repeatable> |
Arguments to pass to the function |
Returns:
Promise which resolves to a success value
- Type
- Promise
waitForFunction(expression, optionsopt, …parameteropt) → {Promise}
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
expression |
function | string |
Function or Expression to be evaluated in the page context |
|||||||||||
options |
object | <optional> |
Properties
|
||||||||||
parameter |
Serializable |
<optional> <repeatable> |
Arguments to pass to the function |
Returns:
Promise which resolves when the function returns a truthy value
- Type
- Promise
(async) waitForNavigation(optionsopt)
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | <optional> |
Properties
|
Fires:
- Page#event:load
waitForSelector(selector, optionsopt) → {Promise.<ElementHandle>}
Wait for the selector to appear in page.
If at the moment of calling the method the selector
already exists,
the method will return
immediately.
If the selector doesn't appear
after the timeout milliseconds of waiting,
the
function will throw.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
selector |
string |
A selector of an element to wait for |
|||||||||||
options |
object | <optional> |
Properties
|
Returns:
Promise which resolves when element specified by selector string is added to DOM
- Type
- Promise.<ElementHandle>