Search code examples
keyboardkeypresspuppeteerenter

Enter button keypress in Puppeteer


I am working on Puppeteer and using keyboard. I get stuck when typing some destination in search box then I find. There are two action:

  1. await page.keyboard.press('ArrowDown');
  2. await page.keyboard.press('Enter'); Then I got result: Image when search location using api Google

Problem is 'Enter' button seem not really working with the suggest destination when the code await page.keyboard.press('Enter'); run. It can not find this destination by auto.

But I tried to search by manually, 'ArrowDown' press and 'Enter' press, then I can find the destination by manually.

Can you help me find out solution and solve it? Thank you so much.


Solution

  • The OP seems to want to have the Enter keypress not go to the original search field, but to the DIV of postal addresses that Google Maps generates in response to his Puppeteer bot typing the first few letters of a street name or similar. So he wants to confirm a Google Maps search suggestion.

    So the solution is to first type in a few letters into the search field, scan the DOM tree anew, to find that DIV that appeared in response to the keypresses, then press arrow down until the desired entry is selected, and send the Enter keypress to it, instead of sending it to the original Search field.