Home > Mobile >  How to avoid that Playwright ignore multiple key press
How to avoid that Playwright ignore multiple key press

Time:01-31

I have a test that is structured as follows.

1. Press Enter 10x.
2. check that element XYZ is in focus.

The keyboard.press is inside a for loop.

The problem is that due to the press speed, the browser does not recognize all of them.

At the end of the test, ENTER was pressed only 8-9 times. I solved it with a sleep function inside the for loop.

for(...){
 this.page.keyboard.press(enter)
 sleep(300)
}

Is it possible to avoid a sleep function here and still get a stable test?

CodePudding user response:

You can add a delay as option in your page.keyboard.press(). So something like this might work for you:

await page.keyboard.press('Enter', { delay: 10 });
  • Related