简体   繁体   中英

TestCafe-use dispatchevent to press Digit1 and Numpad1

Gretting all.In TestCafe,there are pressKey() and dispatchevent() to use on press keyboard.I'm now struggling on one thing:I can't press the Numpad by neither pressKey() or dispatchevent() .Here's what I've tried:

.dispatchEvent(#textbox,'keydown',{code:'numpad1'})

This actually fired,but it didn't type in the text 1 by the numpad1 .Same thing on Digit1 .Want to know if TestCafe support the different pressKey by Numpad and Digit?Thanks for reply.

Edit: I tried to use dispatchevent() Here to fire Digit1 and numpad1 ,it works good,but if i tried on www.google.com,it fails.

Typing text via dispatching keyboard events is not allowed due to security reasons. See: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Auto-repeat_handling_prior_to_Gecko_5.0 . That's why the 'keydown' event is raised, but no value appears in the text box.

To simulate an input process with required key events, you can use the approach described here: https://stackoverflow.com/a/69917022/10684943 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM