2

I just upgraded to Selenium 2 and having trouble simulating a keypress in firefox (maybe other browsers?). First of all, the new API, using IWebDrivers, does not provide a keypress funktion. I can acquire a ISelenium instance with the 1.0 API (WebDriverBackedSelenium) functions, however I receive an error when using this. E.g.

new WebDriverBackedSelenium(driver, TestServerUrl).KeyDownNative("27");

yields

System.NotSupportedException : keyDownNative

The same is the case for KeyDown, KeyPress etc. Is this not supported in Selenium v2?

Thanks in advance!

/Jasper

2 Answers 2

1

Ok so to future reader - I read some of ThoughtWorks documentation and the Selenium v2 API is not quite implemented yet.

So note to self - Big difference between v1 and v2 and v2 API not fully implemented.

Sign up to request clarification or add additional context in comments.

1 Comment

New discovery - e.g. use .SendKeys(Keys.ArrowDown)
0

To send key presses to an WebElement using Selenium 2 (i.e. to an input field) you can do the following:

// Retrieve the required WebElement object of interest //
WebElement myElement = getWebelement();

// send some chars
myElement.sendKeys("Some Test Text");

Also, to delete text from a WebElement (i.e. an input box) you could do the following:

String BACK_SPACE_UNICODE_CODE = "\u0008";

WebElement inputElement = getWebelement();
String currentValue = inputElement.getAttribute("value");

if (!"".equals(currentValue))
{
    for (int count=0;count< currentValue.length();count++)
    {
        inputElement.sendKeys(BACK_SPACE_UNICODE_CODE);
    }            
}

Probably best to put this code within a function so it can be used throughout your tests.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.