admin管理员组文章数量:1426072
I am using puppeteer for scraping a website.
I only have simple problem with the following code:
await page.keyboard.type(data)
await page.click(buttonSelector)
The first line types really long text and I want the second line which is the submit button click to wait until typing is finished.
I am using puppeteer for scraping a website.
I only have simple problem with the following code:
await page.keyboard.type(data)
await page.click(buttonSelector)
The first line types really long text and I want the second line which is the submit button click to wait until typing is finished.
Share Improve this question edited Sep 5, 2024 at 16:07 VLAZ 29.2k9 gold badges63 silver badges84 bronze badges asked Jul 2, 2021 at 5:36 Mostafa SobhMostafa Sobh 491 silver badge6 bronze badges 1-
2
Maybe try
page.waitForFunction()
before submitting. In the checking function you can pare if the current value of the input is equal to the needed data. – vsemozhebuty Commented Jul 2, 2021 at 14:47
2 Answers
Reset to default 3Try to use:
await page.type(".your-selector", "your data", {delay: 10})
and set the required delay or as an alternative:
await page.evaluate(() => document.querySelector(".your-selector").value = "your data")
This will wait for any length of input and continue as quickly as possible.
const textbox = await page.$(".selector");
await textbox.type(textToType);
await page.waitForFunction(
(element, textToType) => {
return element.value === textToType;
},
{}, // here you can customize how it waits (use polling,etc.)
textbox,
textToType
);
本文标签: javascriptPuppeteer wait for keyboardtype to finish typing long textStack Overflow
版权声明:本文标题:javascript - Puppeteer wait for keyboard.type to finish typing long text - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745412523a2657535.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论