【问题标题】:Get HTML elements in nested HTML获取嵌套 HTML 中的 HTML 元素
【发布时间】:2019-07-06 10:32:26
【问题描述】:

页面结构如下:

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

如何单击按钮继续2?

我正在尝试使用 expect-puppeteer。但是,如果您有 puppeteer 的解决方案,那么我会使用它。

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

【问题讨论】:

  • 嵌套文档是 iframe 的一部分吗?
  • 你能以某种方式识别 iFrame 吗?
  • 是 id="iframe-1"

标签: javascript html node.js puppeteer


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    尝试删除第二个和标签。我不确定,但也许它有效。

    【讨论】:

    • 这不是答案,而是评论。我知道,作为新的贡献者,您没有足够的声誉离开 cmets,所以只需回答您可以回答的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多