javascript - 获取嵌套 HTML 中的 HTML 元素
问题描述
该页面具有以下结构:
<html>
<body>
...
<button class="myclass1" type="button">Continue1</button>
...
#document
<html>
<body>
<button class="myclass" type="button">Continue2</button>
如何单击按钮 Continue2?
我正在尝试使用expect-puppeteer。但是,如果您有 puppeteer 的解决方案,那么我会使用它。
await expect(page).toClick('button', { text: 'Continue2'}); // not work(Nested html)
await expect(page).toClick('button', { text: 'Continue1'}); // work
解决方案
您需要先检测帧,然后使用它而不是page
. 在 puppeteer 中:
const frame = page.frames().find(frame => frame.name() === 'iframe-1');
await frame.click('button.myclass');
推荐阅读
- javascript - 如何在oauth2.0进程中实现基于token的认证
- c# - C#本地数据库错误
- python-3.x - 将 CSV 文件读入字典 (KeyError: '","')
- c# - 不使用 JSON.Net 反序列化 odata 响应
- python - 这是一个合理的基准吗
- java - Android:WifiP2PManager 如何将 peerList 添加到 ListView
- angular - AuthGuard 刷新后重定向到登录
- reactjs - 调度 Redux 操作是否被认为是昂贵的?
- powershell - 合并.txt 文件的powershell文件名作为值
- c# - 以编程方式验证 Umbraco 后台用户