Frame

Frame

new Frame(page, webviewElement, frameInfo)

Source:
Parameters:
Name Type Description
page Page

所属page实例

webviewElement WebviewTag

webview节点

frameInfo FrameInfo

frame的信息

Methods

addScriptTag(options) → {Promise.<ElementHandle>}

Source:
Properties:
Name Type Attributes Description
options.url string <optional>

要添加的script的src

options.content string <optional>

要注入页面的js代码

options.waitLoad boolean <optional>

如果是url,等待onload回调

options.type string <optional>

type属性,如果要注入 ES6 module,值为'module'

注入一个指定url或(content)的script标签到页面

Parameters:
Name Type Description
options Object
Returns:

返回注入脚本的dom句柄实例

Type
Promise.<ElementHandle>

addStyleTag(options) → {Promise.<ElementHandle>}

Source:
Properties:
Name Type Attributes Description
options.url string <optional>

要添加的css link的src

options.content string <optional>

要注入页面的style代码

注入一个link(url)或style(content)标签到页面

Parameters:
Name Type Description
options Object
Returns:

返回注入样式的dom句柄实例

Type
Promise.<ElementHandle>

childFrames()

Source:

获取当前frame

content() → {string}

Source:

todo 获取frame的内容

Returns:
Type
string

evaluate(pageFunction, args, timeoutopt) → {Promise.<*>}

Source:

在frame运行指定函数

Parameters:
Name Type Attributes Description
pageFunction function
args Array.<string> | Array.<number>

传给pageFunction的参数

timeout number <optional>

等待超时时间

Returns:

返回运行结果,若pageFunction返回Promise,会等待Promise的resolve结果

Type
Promise.<*>

(async) goto(url, optionsopt) → {Promise.<undefined>}

Source:
Properties:
Name Type Attributes Description
options.waitUntil string <optional>

认定跳转成功的事件类型 load|domcontentloaded,默认为domcontentloaded

options.timeout number <optional>

超时时间,单位为ms,默认为10000ms

控制当前frame跳转到指定url 会在超时时间内追踪重定向,直到跳转到最终页面

Parameters:
Name Type Attributes Description
url string
options Object <optional>
Returns:
Type
Promise.<undefined>

isDetached()

Source:

todo

name() → {string}

Source:

frame的名称

Returns:
Type
string

page() → {Page}

Source:

frame所属的page实例

Returns:
Type
Page

parentFrame() → {Frame}

Source:

frame的parentFrame 如果当前frame为mainFrame,返回null

Returns:
Type
Frame

select()

Source:

todo

setContent(html) → {Promise.<undefined>}

Source:

todo 设置页面内容

Parameters:
Name Type Description
html string
Returns:
Type
Promise.<undefined>

title() → {string}

Source:

frame的标题

Returns:
Type
string

type(selector, text, optionsopt)

Source:
Properties:
Name Type Attributes Description
options.delay number <optional>

// 延迟输入, 操作更像用户

todo 未实现,请使用press方法 输入指定内容

Parameters:
Name Type Attributes Description
selector string

要输入的dom的选择,input或textarea

text string

输入的文本

options Object <optional>

url() → {string}

Source:

获取url,如果是mainFrame为当前url,如果是iframe,则是src属性

Returns:
Type
string

waitFor(selectorOrFunctionOrTimeout, options, …args)

Source:

waitForSelector|waitForFunction|setTimeout的结合体

Parameters:
Name Type Attributes Description
selectorOrFunctionOrTimeout string | number | function
options Object
args any <repeatable>

waitForFunction(pageFunction, optionsopt, …args) → {Promise.<boolean>}

Source:
Properties:
Name Type Attributes Description
options.timeout number <optional>

等待时间

在指定时间内轮询执行方法,直到方法返回true

Parameters:
Name Type Attributes Description
pageFunction function
options Object <optional>
args any <repeatable>
Returns:

成功返回resove(true),超时返回reject

Type
Promise.<boolean>

waitForNavigation(optionsopt) → {Promise.<Object>}

Source:
Properties:
Name Type Attributes Description
options.waitUntil string <optional>

认定跳转成功的事件类型 load|domcontentloaded,默认为domcontentloaded

options.timeout number <optional>

超时时间,单位为ms,默认为10000ms

等待跳转完成

Parameters:
Name Type Attributes Description
options Object <optional>
Returns:

返回跳转后frame的信息

Type
Promise.<Object>

waitForSelector(selector, optionsopt) → {Promise.<undefined>}

Source:
Properties:
Name Type Attributes Description
options.visible boolean <optional>

节点是否可见,如果visible为true时必须查到到dom节点且可见才会返回true

options.timeout number <optional>

超时时间,单位为ms,默认为10000ms

在指定时间内轮询查询dom节点,直到查找到节点

Parameters:
Name Type Attributes Description
selector string

dom节点选择器

options Object <optional>
Returns:

成功则resolve,失败返回reject

Type
Promise.<undefined>

waitForXPath()

Source:

todo

click(selector, options) → {Promise.<boolean>}

Source:

点击frame内的指定节点

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

focus(selector, options) → {Promise.<boolean>}

Source:

聚焦frame内的指定节点

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

blur(selector, options) → {Promise.<boolean>}

Source:

取消聚焦frame内的指定节点

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

hover(selector, options) → {Promise.<boolean>}

Source:

鼠标移入frame内的指定节点,对应mouseover事件

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

tap()

Source:

todo

localStorageKeys()

Source:

获取localStorage的所有key集合

localStorageGet(key) → {Promise.<string>}

Source:

localStorage.getItem

Parameters:
Name Type Description
key string
Returns:
Type
Promise.<string>

localStorageSet(key, value) → {Promise.<undefined>}

Source:

localStorage.setItem

Parameters:
Name Type Description
key string
value string
Returns:
Type
Promise.<undefined>

localStorageRemove(key) → {Promise.<undefined>}

Source:

localStorage.removeItem

Parameters:
Name Type Description
key string
Returns:
Type
Promise.<undefined>

$()

Source:

$$()

Source:

$eval()

Source:

$$eval()

Source:

$x()

Source:

Frame

Frame Frame类,webview的iframe,主页面是mainFrame

Constructor

new Frame()

Source:
Properties:
Name Type Description
webview WebviewTag
isMainFrame boolean

是否mainFrame

ipc Ipc

ipc通信实例,可用于和webview内内容通信

document ElementHandle

当前frame的document操作句柄

Extends

Methods

addScriptTag(options) → {Promise.<ElementHandle>}

Source:
Properties:
Name Type Attributes Description
options.url string <optional>

要添加的script的src

options.content string <optional>

要注入页面的js代码

options.waitLoad boolean <optional>

如果是url,等待onload回调

options.type string <optional>

type属性,如果要注入 ES6 module,值为'module'

注入一个指定url或(content)的script标签到页面

Parameters:
Name Type Description
options Object
Returns:

返回注入脚本的dom句柄实例

Type
Promise.<ElementHandle>

addStyleTag(options) → {Promise.<ElementHandle>}

Source:
Properties:
Name Type Attributes Description
options.url string <optional>

要添加的css link的src

options.content string <optional>

要注入页面的style代码

注入一个link(url)或style(content)标签到页面

Parameters:
Name Type Description
options Object
Returns:

返回注入样式的dom句柄实例

Type
Promise.<ElementHandle>

childFrames()

Source:

获取当前frame

content() → {string}

Source:

todo 获取frame的内容

Returns:
Type
string

evaluate(pageFunction, args, timeoutopt) → {Promise.<*>}

Source:

在frame运行指定函数

Parameters:
Name Type Attributes Description
pageFunction function
args Array.<string> | Array.<number>

传给pageFunction的参数

timeout number <optional>

等待超时时间

Returns:

返回运行结果,若pageFunction返回Promise,会等待Promise的resolve结果

Type
Promise.<*>

(async) goto(url, optionsopt) → {Promise.<undefined>}

Source:
Properties:
Name Type Attributes Description
options.waitUntil string <optional>

认定跳转成功的事件类型 load|domcontentloaded,默认为domcontentloaded

options.timeout number <optional>

超时时间,单位为ms,默认为10000ms

控制当前frame跳转到指定url 会在超时时间内追踪重定向,直到跳转到最终页面

Parameters:
Name Type Attributes Description
url string
options Object <optional>
Returns:
Type
Promise.<undefined>

isDetached()

Source:

todo

name() → {string}

Source:

frame的名称

Returns:
Type
string

page() → {Page}

Source:

frame所属的page实例

Returns:
Type
Page

parentFrame() → {Frame}

Source:

frame的parentFrame 如果当前frame为mainFrame,返回null

Returns:
Type
Frame

select()

Source:

todo

setContent(html) → {Promise.<undefined>}

Source:

todo 设置页面内容

Parameters:
Name Type Description
html string
Returns:
Type
Promise.<undefined>

title() → {string}

Source:

frame的标题

Returns:
Type
string

type(selector, text, optionsopt)

Source:
Properties:
Name Type Attributes Description
options.delay number <optional>

// 延迟输入, 操作更像用户

todo 未实现,请使用press方法 输入指定内容

Parameters:
Name Type Attributes Description
selector string

要输入的dom的选择,input或textarea

text string

输入的文本

options Object <optional>

url() → {string}

Source:

获取url,如果是mainFrame为当前url,如果是iframe,则是src属性

Returns:
Type
string

waitFor(selectorOrFunctionOrTimeout, options, …args)

Source:

waitForSelector|waitForFunction|setTimeout的结合体

Parameters:
Name Type Attributes Description
selectorOrFunctionOrTimeout string | number | function
options Object
args any <repeatable>

waitForFunction(pageFunction, optionsopt, …args) → {Promise.<boolean>}

Source:
Properties:
Name Type Attributes Description
options.timeout number <optional>

等待时间

在指定时间内轮询执行方法,直到方法返回true

Parameters:
Name Type Attributes Description
pageFunction function
options Object <optional>
args any <repeatable>
Returns:

成功返回resove(true),超时返回reject

Type
Promise.<boolean>

waitForNavigation(optionsopt) → {Promise.<Object>}

Source:
Properties:
Name Type Attributes Description
options.waitUntil string <optional>

认定跳转成功的事件类型 load|domcontentloaded,默认为domcontentloaded

options.timeout number <optional>

超时时间,单位为ms,默认为10000ms

等待跳转完成

Parameters:
Name Type Attributes Description
options Object <optional>
Returns:

返回跳转后frame的信息

Type
Promise.<Object>

waitForSelector(selector, optionsopt) → {Promise.<undefined>}

Source:
Properties:
Name Type Attributes Description
options.visible boolean <optional>

节点是否可见,如果visible为true时必须查到到dom节点且可见才会返回true

options.timeout number <optional>

超时时间,单位为ms,默认为10000ms

在指定时间内轮询查询dom节点,直到查找到节点

Parameters:
Name Type Attributes Description
selector string

dom节点选择器

options Object <optional>
Returns:

成功则resolve,失败返回reject

Type
Promise.<undefined>

waitForXPath()

Source:

todo

click(selector, options) → {Promise.<boolean>}

Source:

点击frame内的指定节点

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

focus(selector, options) → {Promise.<boolean>}

Source:

聚焦frame内的指定节点

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

blur(selector, options) → {Promise.<boolean>}

Source:

取消聚焦frame内的指定节点

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

hover(selector, options) → {Promise.<boolean>}

Source:

鼠标移入frame内的指定节点,对应mouseover事件

Parameters:
Name Type Description
selector string

选择器

options Object

暂不支持

Returns:
Type
Promise.<boolean>

tap()

Source:

todo

localStorageKeys()

Source:

获取localStorage的所有key集合

localStorageGet(key) → {Promise.<string>}

Source:

localStorage.getItem

Parameters:
Name Type Description
key string
Returns:
Type
Promise.<string>

localStorageSet(key, value) → {Promise.<undefined>}

Source:

localStorage.setItem

Parameters:
Name Type Description
key string
value string
Returns:
Type
Promise.<undefined>

localStorageRemove(key) → {Promise.<undefined>}

Source:

localStorage.removeItem

Parameters:
Name Type Description
key string
Returns:
Type
Promise.<undefined>

$()

Source:

$$()

Source:

$eval()

Source:

$$eval()

Source:

$x()

Source: