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
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);
Comments
why not use send keys.
driver.findelement(by.xpath(xpathExpr)).sendkeys("1999");
1 Comment
Ibexy I
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"
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
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");
answered Apr 4, 2018 at 12:26