How can I emulate TAB key with Selenium 2.0?

16,818 views
Skip to first unread message

gadhet

unread,
Dec 9, 2010, 3:23:22 AM12/9/10
to webdriver
Hi all,

I'm using Selenium 2.0a7(aka Webdriver) and I have problem with
emulate TAB key. I've founded something like this:

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

but it doesn't work.

Can anyone help me with this, please?

Jason Leyba

unread,
Dec 9, 2010, 3:42:26 AM12/9/10
to webd...@googlegroups.com
Use the org.openqa.selenium.Keys enum:

WebElement element = driver.findElement(By.id("inputField"));
element.sendKeys(Keys.TAB);


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Simon Stewart

unread,
Dec 9, 2010, 5:50:36 AM12/9/10
to webd...@googlegroups.com
Or:

element.sendKeys("\t");

Simon

gadhet

unread,
Dec 9, 2010, 9:06:26 AM12/9/10
to webdriver
Thank you Jason and Simon but I have following problem:

FAILED: TAB_key
org.openqa.selenium.NoSuchElementException: Unable to locate element:
{"method":"id","selector":"inputField"}
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_05'
Driver info: driver.version: firefox
at
org.openqa.selenium.firefox.Response.ifNecessaryThrow(Response.java:
105)
at
org.openqa.selenium.firefox.FirefoxDriver.sendMessage(FirefoxDriver.java:
296)
at
org.openqa.selenium.firefox.FirefoxDriver.sendMessage(FirefoxDriver.java:
290)
at
org.openqa.selenium.firefox.FirefoxDriver.findElement(FirefoxDriver.java:
249)
at
org.openqa.selenium.firefox.FirefoxDriver.findElementById(FirefoxDriver.java:
177)
at org.openqa.selenium.By$1.findElement(By.java:66)
at
org.openqa.selenium.firefox.FirefoxDriver.findElement(FirefoxDriver.java:
173)
at selenium_project.SeleniumXX.TAB_key(SeleniumXX.java:37)
... Removed 26 stack frames


And it still doesn't work

On 9 Gru, 11:50, Simon Stewart <simon.m.stew...@gmail.com> wrote:
> Or:
>
> element.sendKeys("\t");
>
> Simon
>
> On Thu, Dec 9, 2010 at 8:42 AM, Jason Leyba <jmle...@gmail.com> wrote:
> > Use the org.openqa.selenium.Keys enum:
>
> > WebElement element = driver.findElement(By.id("inputField"));
> > element.sendKeys(Keys.TAB);
>

Aaron

unread,
Dec 10, 2010, 11:58:37 AM12/10/10
to webdriver
If you get this error from Jason's code, then it looks like it can't
find the element correctly. Do you have the right ID for the element
you are looking for. Jason didn't mean to actually use "inputField" as
the id. You have to find the id/xpath/name/etc of your element, and
tell the driver to find it.

In other words, this NoSuchElementException is one the first line of
code, the one where you find the element. The error is NOT with the
second line of code, where you send the tab key.
Reply all
Reply to author
Forward
0 new messages