簡體   English   中英

獲取嵌套 HTML 中的 HTML 元素

[英]Get HTML elements in nested 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');

嘗試刪除第二個和標簽。 我不確定這一點,但也許它有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM