最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

以嵌套HTML格式获取HTML元素

IT培训 admin 8浏览 0评论

以嵌套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');

以嵌套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. 暂无评论