Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium SendKeys not working for open brackets and harsh keys when using java

I have using selenium webdriver 2.33.0 and i have a requirement of sending data with the following characters inside the data ("(", "#")

When we tried to send these characters using sendkeys

"WebElement dat = driver.findElement(By.xpath("xpathexpression);
dat.sendkeys("select * from (?s, ?p, ?o)");

The following data gets displayed in the textarea as select * from ?s, ?p, ?o) the open bracket is missing. I have used selenium actions class sendkeys and robot sendkeys also.

I am not able to fix the issue. Can someone help me on this?

like image 247
Venkatachalam Neelakantan Avatar asked Dec 19 '25 15:12

Venkatachalam Neelakantan


2 Answers

Ugly but efficient workaround: replace the opening brackets ( with the key sequence shift + 9, as suggested by user2935099.

dat.sendKeys(Keys.chord(Keys.SHIFT, "9"));

Funnily, this seems to work regardless of your current keyboard layout (I use an Irish locale with a French layout).


I stumbled upon this one with version 2.40.0, and it is definitely a bug in Selenium. Using the following in the Firefox JavaScript console works flawlessly:

 var box = getElementById('SearchBox');
 box.setValue('AB (CDE FGH)');
like image 100
David M. Avatar answered Dec 24 '25 10:12

David M.


The issue is resolved when using actions class

WebElement dat = driver.findElement(By.xpath("xpathexpression"); 
dat.click(); 
Actions data = new Actions(driver);
data.sendKeys(Keys.chord(Keys.CONTROL,"a"),Keys.DELETE);
data.perform();
query = query.replaceAll("\\(", Keys.chord(Keys.SHIFT,"9")); 
query = query.replaceAll("\\#", Keys.chord(Keys.SHIFT,"3")); 
query = query.replaceAll("\\-", Keys.SUBTRACT.toString()); 
query = query.replaceAll("\\}", Keys.chord(Keys.SHIFT,"]")); 
data.sendKeys(query); 
data.perform();
like image 39
Venkatachalam Neelakantan Avatar answered Dec 24 '25 11:12

Venkatachalam Neelakantan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!