Reputation: 49
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.
Upvotes: 3
Views: 6628
Reputation: 672
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
);
Upvotes: 0
Reputation: 474
Try 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")
Upvotes: 3