Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate TAB keypress event in Selenium RC

I need to simulate a tab keypress in Selenium RC, using the Java API.

I do this after having entered some text using:

selenium.type(input, "mytext");

I've tried 3 alternatives to get the tab working:

selenium.keyPress(input, "\\9");

and:

selenium.focus(input);
selenium.keyPressNative("09");

and even:

selenium.getEval("var evt = window.document.createEvent('KeyboardEvent');evt.initKeyEvent ('keypress', true, true, window,0, 0, 0, 0,0, 9,0);window.document.getElementsByTagName('input')[2].dispatchEvent(evt);")

The best I can get is a "tab space" to be inserted after my text so I end up with this in the input field:

"mytext    "

What I actually want is to tab to the next control. Any clues? Thanks!

(Note: I have to use tab and can not use focus or select to chose the element I want to go to, for various reasons, so no suggestions along these lines please!)

like image 887
Joel Avatar asked Jun 29 '10 12:06

Joel


1 Answers

selenium.keyPressNative(java.awt.event.KeyEvent.VK_TAB + ""); 

I don't use the Java API, but this post from google groups suggests it is your solution. I can't imagine that "9" is different from "09" in your question, but give it a try?

like image 158
Ryley Avatar answered Oct 14 '22 10:10

Ryley