react$$
react$$ 命令是一个有用的命令,用于通过实际名称查询多个 React 组件,并通过 props 和 state 进行筛选。
信息
该命令仅适用于使用 React v16.x 的应用程序。在 Selectors 指南中了解 更多关于 React 选择器的信息。
用法
browser.react$$(selector, { props, state })
参数
| 名称 | 类型 | 详情 | 
|---|---|---|
| selector | string | React 组件名称 | 
| options可选 | ReactSelectorOptions | React 选择器选项 | 
| options.props可选 | Object | 元素应包含的 React props | 
| options.state可选 | Array<any>, number, string, object, boolean | 元素应处于的 React state | 
示例
pause.js
it('should calculate 7 * 6', async () => {
    await browser.url('https://ahfarmer.github.io/calculator/');
    const orangeButtons = await browser.react$$('t', {
        props: { orange: true }
    })
    console.log(await orangeButtons.map((btn) => btn.getText()));
    // prints "[ '÷', 'x', '-', '+', '=' ]"
});
返回值
- <WebdriverIO.ElementArray>