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
We can also perform a CTRL+A press by simply using the sendKeys() method. We have to pass Keys. CONTROL along with the string A by concatenating with +, as an argument to the method.
Now, as we discussed, Selenium WebDriver provides two ways to send any keyboard event to a web element: sendKeys() method of WebElement class. Actions class.
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);
why not use send keys.
driver.findelement(by.xpath(xpathExpr)).sendkeys("1999");
Try this. It works for me!
driver.findelement(by.xpath(xpathExpr)).SendKeys(keys.NumberPad1+keys.NumberPad9+keys.NumberPad9+keys.NumberPad9);
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With