4

I am testing site with selenium and I need to send an e-mail to one of the fields. So far I am using this Java method:

 String email = "test@example.com"
 WebElement emailField = driver.findElement(By.id("mainForm:accountPanelTabId:1:accountEmails");
 emailField.sendKeys(email);

But from (to me) uknown reason, this is sending exactly this value to the field:

testvexample.com

(so basically the "@" got replaced by "v")

Just out of curiosity: I am Czech and have Czech keyboard. One shortcut to write "@" symbol is rightAlt + v so I believe this can be connected...

So I am searching any "bulletproof" methot which always writes "@" symbol. Any help appreciated.

EDIT the sendKeys is method of Selenium, and it simulates typing on keyboard. The javadoc is here: http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#sendKeys%28java.lang.CharSequence...%29

Pavel Janicek
  • 14,128
  • 14
  • 53
  • 77

1 Answers1

0

The following should work: String email = "test\u0040example.com";

Apologies for misreading the question earlier.

I think you will have to call sendKeys using the proper values from the Keys enum to simulate the way you get your at-sign. Use Keys.ALT with your "v" in a chord:

sendKeys(Keys.chord(Keys.ALT, "v"));
Ray Toal
  • 86,166
  • 18
  • 182
  • 232
  • bad news... still the same :( – Pavel Janicek Aug 25 '11 at 07:36
  • Sorry to hear that. That means the `sendKeys` method is doing something to your string. And here I was thinking that you had a strange font. ;-) Can you get to the source code for `sendKeys`? – Ray Toal Aug 25 '11 at 07:41
  • Javadoc is here: http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#sendKeys%28java.lang.CharSequence...%29 – Pavel Janicek Aug 25 '11 at 07:47
  • Got me to the solution: When I changed my keyboard defaults from "Czech" to "English" (so now, the English Keyboard is the default one), the original code started working. Thanks a lot for help! – Pavel Janicek Aug 25 '11 at 08:27
  • Late to party, but right combination is Keys.chord(Keys.ALT, Keys.CONTROL, "v"), as rightAlt usually works like ALT+CTRL. – Jan Zdrha Sep 06 '18 at 20:40