Skip to content

page - puppeteerApp

In the Android app, you can run and call Kotlin code. Page By default, a page object has been instantiated, and you can use it directly. For example, await page.click('#id');

page.title() ⇒ *

Get the name of the current app, such as WeChat.

Returns: * - {Promise<string>}

page.url() ⇒ *

Get the package name of the current app, such as WeChat.

Returns: * - {Promise<string>} , for example,com.tencent.mm/android.widget.FrameLayout

page.goto(activityFullName) ⇒ *

Jump to the activity of the specified app

Returns: * - {Promise<void>}

ParamType
activityFullNamestring

page.$(selector) ⇒ *

Get the specified element. If the element does not exist, return null. If there are multiple, return the first one.

Returns: * - {Promise<any>}

ParamType
selectorstring

Example

js
let ele = await page.$('#bkk');
let item = await page.$("=收藏按钮");
item.click();
console.log("item:" , JSON.stringify(item) );

page.$$(selector) ⇒ *

Get all specified elements, return an array.

Returns: * - {Promise<any[]>}

ParamType
selectorstring

Example

js
let eles = await page.$$('#bkk');

page.click(selector, [options]) ⇒ *

Click on the specified element.

Returns: * - {Promise<void>}

ParamTypeDefault
selectorstring
[options]ClickOptions{ clickCount: 1, delay: 100 }

Example

js
await page.click('#bkk');

page.evaluate(pageFunction, ...args) ⇒ Promise.<Serializable>

Execute the specified method on the page. Similar to the eval() method.

Returns: Promise.<Serializable> - The result of pageFunction execution.

ParamTypeDescription
pageFunctionfunction | stringThe method to be executed in the context of the page instance.
...args*The parameters to be passed to pageFunction.

page.waitForSelector(selector, options) ⇒ Promise.<AppElement>

The selector of the element to wait for. Waiting for the element matching the specified selector to appear on the page. If the matching element already exists when this method is called, it immediately returns. If the specified selector still does not appear after the timeout period, this method will throw an error.

Returns: Promise.<AppElement> - Returns a Promise that resolves to an AppElement object.

ParamTypeDescription
selectorstringThe selector of the element to wait for. It is the same as the parameter of document.querySelector(). css selector syntax. #id,.class,[attr=value],=text, >=text

| options | Object | Optional parameter: | | options.timeout | number | Timeout, unit milliseconds, default is 30000. | | options.pollingInterval | number | pollingInterval, unit milliseconds, default is 100. |

Example

js
await page.waitForSelector('#bkk');
await page.waitForSelector('#bkk', { timeout: 10000 });
await page.waitForSelector('.android.view.View[text="love reading"]')
await page.waitForSelector('.View[text="love reading"]');
let element = await page.waitForSelector('.View[text="love reading"]');
await element.click();

page.waitForFunction(pageFunction, [options], ...args) ⇒ *

Wait for the return value of pageFunction to be true. If it times out, an error will be thrown. waitForFunction can be used to monitor changes in the size of the page and screen rotation.

ParamTypeDefaultDescription
pageFunction*The method to be executed in the context of the page instance.
[options]Object{ timeout: 30000, pollingInterval: 100 }
...args*

Example

js
await page.waitForFunction(()=> Device.rotation() !=0 );

page.type(selector, text, [options]) ⇒ Promise.<void>

Input text in the specified element on the page.

Returns: Promise.<void> - Returns a Promise that resolves when the input operation is complete.

ParamTypeDefaultDescription
selectorstringThe element selector for the content to be input. If there are multiple matching elements, the input will be entered into the first matching element.
textstringThe text to be input.
[options]Object{ delay: 0, autoCorrect: true }Optional parameters.
[options.delay]number0The delay time between inputting texts (in milliseconds). Default is 0.
[options.autoCorrect]booleantrueSpecifies whether to automatically correct the input text. Default is true.

Example

js
await page.type('#bkk', 'test.844.ai');

page.screenshot([options]) ⇒ Promise.<string>

Take a screenshot of the current page.

Returns: Promise.<string> - - A Promise object that resolves to the base64 string of the screenshot.

ParamTypeDefaultDescription
[options]Object{}Optional configuration parameters:
[options.path]stringScreenshot save path. The file extension determines the image type. Relative paths are resolved from the current path. If no path is specified, it is not saved to the hard drive.
[options.type]string"'png'"Specify the screenshot type, which can be 'jpeg' or 'png'. Default is 'png'.
[options.quality]numberImage quality (0-100), only applicable to jpeg type.
[options.clip]ObjectSpecify a cropping area,
[options.clip.x]numberTop left corner x coordinate of the cropping area.
[options.clip.y]numberTop left corner y coordinate of the cropping area.
[options.clip.width]numberWidth of the cropping area.
[options.clip.height]numberHeight of the cropping area.
[options.omitBackground]booleanfalseWhether to hide the default white background and make it transparent. Default is opaque.
[options.encoding]string"'binary'"Image encoding type, can be 'base64' or 'binary'. default 'binary'。

page.clicks(selectors, options)

Easy to click multiple elements. Such as inputting the amount, password.

ParamType
selectors*
options*

Example

js
await page.clicks(['=1', '=.', '=8', '=8']);

Example

js
await page.clicks(['=1', '=.', '=8', '=8'], { delay: 200 });

Example

js
await page.clicks('1.88');

page.tap(x, y, [options]) ⇒ Promise.<void>

Perform a tap operation at the specified coordinate position.

Returns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position
[options]Object{}Optional configuration parameters
[options.clickCount]number1Number of taps, default is 1
[options.delay]number50Delay time between taps (milliseconds), default is 50
[options.interval]number100Interval time between each tap (milliseconds), default is 100
[options.left]number | nullTop left corner x coordinate of the cropping area.If left, top, width, and height are set, then coordinates will be randomly generated within that area.
          |

| [options.top] | number | null | | Top left corner y coordinate of the area. | | [options.width] | number | null | | Width of the area. | | [options.height] | number | null | | Height of the area. |

page.tapText(text, [options]) ⇒ Promise.<void>

Click on the specified text element. If multiple elements match, click on the first one. Address the issue of page.Click not working and element not found. Improve robustness. Wrap the following code into a method for easy use.

js
let elements = await page.elements()
let item = flatElements(elements).find(item => item.text === 'View leaderboard');
if(item){
    let { left , top , right , bottom  } = item.boundsInScreen ;
    let x = ( left + right ) / 2 ;
    let y = ( top + bottom ) / 2 ;
    await page.tap(  x , y );
}

Returns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xnumbertext,default>=selector。The text supports selector characters. For example:loving reading,=loving reading,or >=loving reading。
[options]Object{}Optional configuration parameters
[options.clickCount]number1Number of taps, default is 1
[options.delay]number50Delay time between taps (milliseconds), default is 50
[options.interval]number100Interval time between each tap (milliseconds), default is 100

page.elements

Get all elements on the current page, The data content is the nodeInfo converted to a JSON object.

Kind: static property of page

page.longTap ⇒ Promise.<void>

Perform a long tap operation at the specified coordinate position. Trigger long press, such as long pressing on an app icon on the phone system's home screen. The interface parameters are similar to page.tap.

Kind: static property of pageReturns: Promise.<void> -A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position
[options]Object{}Optional configuration parameters:
[options.delay]number500Long press delay time (milliseconds), default is 500
[options.left]number | nullTop left corner x coordinate of the area.
[options.top]number | nullTop left corner y coordinate of the area.
[options.width]number | nullWidth of the area.
[options.height]number | nullHeight of the area.

page.touchDown ⇒ Promise.<void>

Simulate the touch operation of pressing down at the specified coordinate position.

Kind: static property of pageReturns: Promise.<void> -A Promise that resolves to indicate completion of the operation.

ParamTypeDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position

page.touchUp ⇒ Promise.<void>

Simulate the touch operation of releasing the specified coordinate position.

Kind: static property of pageReturns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position

page.touchMove ⇒ Promise.<void>

Simulate the touch operation of sliding from one coordinate position to another.

Kind: static property of pageReturns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xFromnumberstart X-axis coordinate position
yFromnumberstart Y-axis coordinate position
xTonumbertarget X-axis coordinate position
yTonumbertarget Y-axis coordinate position
[duration]number200Slide duration (milliseconds), default is 200

page.swipe ⇒ Promise.<void>

Simulate the slide operation of sliding from one coordinate position to another.

Kind: static property of pageReturns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xFromnumberstart X-axis coordinate position
yFromnumberstart Y-axis coordinate position
xTonumbertarget X-axis coordinate position
yTonumbertarget Y-axis coordinate position
[duration]number200Slide duration (milliseconds), default is 200

page.swipeDown ⇒ Promise.<void>

Simulate the operation of sliding down from the specified coordinate position.

Kind: static property of pageReturns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position
[duration]number200Slide duration (milliseconds), default is 200

page.swipeUp ⇒ Promise.<void>

Simulate the operation of sliding up from the specified coordinate position.

Kind: static property of pageReturns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position
[duration]number200Slide duration (milliseconds), default is 200

page.swipeLeft ⇒ Promise.<void>

Simulate the operation of sliding left from the specified coordinate position.

Kind: static property of pageReturns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position
[duration]number200Slide duration (milliseconds), default is 200

page.swipeRight ⇒ Promise.<void>

Simulate the operation of sliding right from the specified coordinate position.

Kind: static property of pageReturns: Promise.<void> - A Promise that resolves to indicate completion of the operation.

ParamTypeDefaultDescription
xnumberX-axis coordinate position
ynumberY-axis coordinate position
[duration]number200Slide duration (milliseconds), default is 200

page.home

Back to the App; default wait 200 milliseconds

Example

js
await page.home();