History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: SRC-385
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Smitha
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Selenium Remote Control

Selenium Key press events

Created: 12/Nov/07 01:36 AM   Updated: 27/Nov/08 07:02 AM
Component/s: Client Driver - Java
Affects Version/s: 0.9.0
Fix Version/s: None

Original Estimate: 96h Remaining Estimate: 96h Time Spent: Unknown
File Attachments: 1. File htmlutils.js (27 kb)

Environment: Linux - Firefox
Issue Links:
Relationship
 
This issue Relates to:
SRC-303 Key events don't work properly Major Open


 Description  « Hide
I am having an issue while working on the Keyboard shortcuts

When i run them manually using browser they are working but when i automate and run the test cases appropriate action is not being executed for the keyboard shortcuts

I am using the following code:

selenium.keyPress(ENTRIES, "j"); // select the first item
selenium.keyPress(ENTRIES, "\106"); // go back to the first item

I have even tried with using the Ascii values instead of characters and used other key events keyUp,KeyDown.

I have tried using the JavaScript keycode values instead of ascii values.

But no action is initiated on the browser for the keyboard shortcut.

I testing on a Linux machine and FireFox browser.

I have tried using

// for "u" and expected action is collapse/expansion of the toggler
 selenium.keyPress(ENTRIES,"85");

// for "r" and expected action page refresh
 selenium.keyPress(ENTRIES,"82");

I even tried using keyUp and keyDown() events for the same values but no action triggered.

Can anyone help me in resolving this issue?


 All   Comments   Work Log   Change History      Sort Order:
Jason Leyba - 14/Dec/07 06:12 PM
The problem is in htmlutil.js for Selenium core (//core/scripts/htmlutil.js)

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.

Jason Huggins - 06/Mar/08 10:09 PM
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)

Dan Fabulich - 06/Mar/08 10:15 PM
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

Dan Nye - 25/Nov/08 08:53 AM

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

Andras Hatvani - 27/Nov/08 06:13 AM
Reducing priority as with the key*Native() functions workaround is available.