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
);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745412523a4626599.html
评论列表(0条)