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