2

As part of a testing framework I'm working on, I need to be able to simulate keyboard events in Chrome. More specifically, I need to fill in the value of an INPUT element. This is relatively easy to do in Firefox, but for some reason Chrome just ignores my generated events. (Well not really ignoring them, see below)

I've reviewed a number of questions here on SO including:

The problem isn't that the events aren't being dispatched (they are) or received (they are) but rather that Chrome isn't inserting the characters into form elements.

Please see this example on JSBin (based on the first URL in the list above which includes a fix for the which/keyCode == 0 issue)

What is Chrome doing with these generated KeyboardEvents and is there a way to convince it to inject the simulated keys into form elements?

Notes:

  • The testing framework is similar in nature to Selenium and needs to simulate keyboard and mouse events in place of user interaction. Due to the nature of the project, this testing framework needs to be custom built and I can't use Selenium at this time
  • Potential solutions cannot require any 3rd party libraries and must work in Chrome 23+
  • At the moment I'm adding a Listener for the keypress event and manually injecting the characters. I'd like to avoid this because I have to inject this extra code at test time.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
psema4
  • 3,007
  • 1
  • 17
  • 22

0 Answers0