最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

以嵌套HTML格式获取HTML元素

运维笔记admin16浏览0评论

以嵌套HTML格式获取HTML元素

以嵌套HTML格式获取HTML元素

该页面具有以下结构:

<html>
 <body>
  ...
  <button class="myclass1" type="button">Continue1</button>
   ...
    #document
     <html>
      <body>
       <button class="myclass" type="button">Continue2</button>

如何单击Continue2按钮?

我正在尝试使用expect-puppeteer。但是,如果你有木偶操作者的解决方案,那么我将使用它。

await expect(page).toClick('button', { text: 'Continue2'}); // not work(Nested html)
await expect(page).toClick('button', { text: 'Continue1'}); // work
回答如下:

您需要先检测帧,然后使用它而不是page。在木偶戏:

const frame = page.frames().find(frame => frame.name() === 'iframe-1');
await frame.click('button.myclass');

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论