|
|
|
At least for Firefox:
I used this handy utility to get the following data: http://unixpapa.com/js/testkey.html What happens when pressing the "y" key (manually, no Selenium involved): keydown keyCode=89 (Y) which=89 (Y) charCode=0 keypress keyCode=0 which=121 (y) charCode=121 (y) keyup keyCode=89 (Y) which=89 (Y) charCode=0 What happens when pressing "F10" key (manually, no Selenium involved): keydown keyCode=121 (y) which=121 (y) charCode=0 keypress keyCode=121 (y) which=0 charCode=0 keyup keyCode=121 (y) which=121 (y) charCode=0 What actually happens while using Selenium with the "typeKeys" command and the value of "y" into a text field: keydown keyCode=121 (y) which=121 (y) charCode=0 keyup keyCode=121 (y) which=121 (y) charCode=0 keypress keyCode=121 (y) which=121 (y) charCode=121 (y) So, yes, for keys sent via "typeKeys" (at least on the keypress method), the keyCode should be set to 0. But there is more involved to make this work completely correctly. Of course, this only applies to Firefox... Getting key events working properly in Safari and IE, too, is whole 'nother sad and sorry story. (Read this for more detail --> http://unixpapa.com/js/key.html) For future reference, you can probably just use the one we have checked in: http://svn.openqa.org/fisheye/browse/~raw,r=HEAD/selenium/trunk/src/main/resources/tests/html/test_form_events.html
This isn't just restricted to Linux boxes, and is still an issue as of 25-Nov-2008. Take the following code - it will quit Firefox when run. Tested in Win XP Pro on both Fx 3.0.4 / IDE 1.0b2, and Fx 2.0.0.18 / IDE 0.9.1. Run against base URL: http://www.google.co.uk/ open / waitForElementPresent xpath=//input[@name='q'] keyPress xpath=//input[@name='q'] y keyPress xpath=//input[@name='q'] f keyPress xpath=//input[@name='q'] x When is a fix for this likely to be put into a released IDE? Dan Reducing priority as with the key*Native() functions workaround is available.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The key events are created using initKeyEvent (http://developer.mozilla.org/en/docs/DOM:event.initKeyEvent). Selenium is converting the character to type into its character code, but then passing it to initKeyEvent as the character code *and* the virtual key code. For certain keys, the virtual key code will have the same value as the character key code, so Firefox will act as if the virtual key was pressed and not the character key.
For example, the character code for 'y' is the same as the virtual key code for F10. So if you did:
selenium.typeKeys("id=textField", "ye")
you should see the Edit menu in Firefox open (F10+e).
I will attach an updated htmlutil.js file that passes 0 for the virtual key code, this should fix the problem.