6

I want to send 1999 to a text box in Selenium WebDriver (java). The following code is not working when I try to combine the key strokes into a string before sendkeys:

String allKeys = Keys.NUMPAD1 + Keys.NUMPAD9 + Keys.NUMPAD9 + Keys.NUMPAD9; 

Am getting this error:

The operator + is undefined for the argument type(s) org.openqa.selenium.Keys, org.openqa.selenium.Keys

asked Sep 23, 2012 at 12:16

4 Answers 4

6

Instead of using:

String allKeys = Keys.NUMPAD1 + Keys.NUMPAD9 + Keys.NUMPAD9 + Keys.NUMPAD9; 

You should use:

driver.findelement(by.xpath(xpathExpr)).sendkeys(Keys.NUMPAD1, Keys.NUMPAD9, Keys.NUMPAD9, Keys.NUMPAD9);

Or use:

String allKeys = "1999";
driver.findelement(by.xpath(xpathExpr)).sendkeys(allKeys);
answered Sep 26, 2012 at 15:02

Comments

2

why not use send keys.

driver.findelement(by.xpath(xpathExpr)).sendkeys("1999");
answered Sep 23, 2012 at 18:47

1 Comment

thanks for all the help. I was actually learning to use the Keys class. yes I could have sent "1999". But I wanted to do it using the "Keys"
2

Try this. It works for me!

driver.findelement(by.xpath(xpathExpr)).SendKeys(keys.NumberPad1+keys.NumberPad9+keys.NumberPad9+keys.NumberPad9);
Sufian
6,55517 gold badges71 silver badges125 bronze badges
answered Jun 25, 2014 at 5:34

Comments

1

Question : How do I send keyboard keys combination in selenium webdriver (java)?

Answer : You can send keyboard keys using below method

Method 1 :

driver.findElement(By.id("Year")).sendKeys(Keys.NUMPAD9);

Method 2 :

String allKeys = "1999";
driver.findElement(By.id("Year")).sendKeys(allKeys);

Method 3 :

driver.findElement(By.id("Year")).sendKeys("1999");

enter image description here

answered Apr 4, 2018 at 12:26

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.