简体   繁体   English

获取嵌套 HTML 中的 HTML 元素

[英]Get HTML elements in nested HTML

The page has the structure:该页面具有以下结构:

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

How can I click a button Continue2?如何单击按钮 Continue2?

I'm trying to use expect-puppeteer.我正在尝试使用expect-puppeteer。 But if you have a solution for puppeteer then I will use it.但是如果你有木偶操作的解决方案,那么我会使用它。

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

You need to detect the frame first, then use it instead of page .您需要先检测框架,然后使用它而不是page In puppeteer :在木偶戏中:

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

Try delete second and tags.尝试删除第二个和标签。 I'm not sure about that, but maybe it works.我不确定这一点,但也许它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM