最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Puppeteer wait for keyboard.type to finish typing long text - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 3

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")

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
);
发布评论

评论列表(0)

  1. 暂无评论