sendKeys(CharSequence) causes issues with Jython/BeanShell

541 views
Skip to first unread message

James Cooper

unread,
Apr 25, 2008, 8:03:41 PM4/25/08
to webdriver
Hi,

One thing I've enjoyed doing in the past is using Jython or BeanShell
to script WebDriver. Last week I upgraded to the latest trunk
revision, and I've found that these scripting tools aren't able to
invoke sendKeys(), presumably because their reflection code isn't
smart enough to find the CharSequence.

Here's the error from BeanShell:

bsh % driver.findElement(By.xpath("//
input[@name='username']")).sendKeys("Hello");

// Error: EvalError: Error in method invocation: Method
sendKeys( java.lang.String ) not found in
class'com.googlecode.webdriver.firefox.FirefoxWebElement' : at Line:
1 : in file: <unknown file> : .sendKeys ( "Hello" )

Jython emits a similar error.

Any reason to use CharSequence and not simply String?

Any way to get BeanShell to figure out how to call sendKeys() ?

thanks!

-- James

Simon Stewart

unread,
Apr 26, 2008, 9:42:58 AM4/26/08
to webd...@googlegroups.com
Hi James,

The reason why sendKeys uses CharSequence is because that's the same
process used to send all key presses. For example:

element.sendKeys("Cheese", Keys.DOWN);

Will simulate the user typing "Cheese" and then hitting the down arrow
on the keyboard.

Those keys that are hard to represent normally are (or will be)
encapsulated in the "Keys"[1] class. We should also provide the
ability to do chording at some point, though that's pretty far down
the list of priorities.

I've not really used BeanShell or Jython, but the signature for
"sendKeys" takes an array of CharSequences (it's declared using the
varargs Java 5 syntax) Perhaps passing in an array of strings might
work?

Regards,

Simon

[1] http://code.google.com/p/webdriver/source/browse/trunk/common/src/java/com/googlecode/webdriver/Keys.java

James Cooper

unread,
Apr 27, 2008, 1:45:35 PM4/27/08
to webdriver
Hi Simon,

Thanks for the explanation. Your suggestion of using an array
worked. Here's a working example in BeanShell:

driver.findElement(By.xpath("//input[@name='username']")).sendKeys(new
String[] { "johndoe"});

thanks!

-- James

On Apr 26, 6:42 am, "Simon Stewart" <simon.m.stew...@gmail.com> wrote:
> Hi James,
>
> The reason why sendKeys uses CharSequence is because that's the same
> process used to send all key presses. For example:
>
> element.sendKeys("Cheese", Keys.DOWN);
>
> Will simulate the user typing "Cheese" and then hitting the down arrow
> on the keyboard.
>
> Those keys that are hard to represent normally are (or will be)
> encapsulated in the "Keys"[1] class. We should also provide the
> ability to do chording at some point, though that's pretty far down
> the list of priorities.
>
> I've not really used BeanShell or Jython, but the signature for
> "sendKeys" takes an array of CharSequences (it's declared using the
> varargs Java 5 syntax) Perhaps passing in an array of strings might
> work?
>
> Regards,
>
> Simon
>
> [1]http://code.google.com/p/webdriver/source/browse/trunk/common/src/jav...
Reply all
Reply to author
Forward
0 new messages