gpt4 book ai didi

Puppeteer - 如何填写 iframe 内的表单?

转载 作者:行者123 更新时间:2023-12-03 15:21:17 29 4
gpt4 key购买 nike

我必须填写一个 iframe 内的表单,这里是 sample page .仅使用 page.focus() 无法访问和 page.type() .我试图通过使用 const formFrame = page.mainFrame().childFrames()[0] 来获取表单 iframe ,这有效,但我无法真正与表单 iframe 交互。

最佳答案

我自己想通了。这是代码。

console.log('waiting for iframe with form to be ready.');
await page.waitForSelector('iframe');
console.log('iframe is ready. Loading iframe content');

const elementHandle = await page.$(
'iframe[src="https://example.com"]',
);
const frame = await elementHandle.contentFrame();

console.log('filling form in iframe');
await frame.type('#Name', 'Bob', { delay: 100 });

关于Puppeteer - 如何填写 iframe 内的表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46529201/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com