Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

java - convert at symbol ("@") to CharSequence

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 = "[email protected]"
 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The following should work: String email = "testu0040example.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"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...