question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SendKeys is not working correctly

See original GitHub issue

Device: Surface Pro AppType: Desktop App Server version: tried on both 1.1.1 and 1.2.0 Client: Java

When I use sendkeys to send a text that contains normal and capitalized characters, all the capitalized characters after the first will be the same as the first. E.g:

  • DemoAccount will be typed as DemoDccount
  • abcdefghABCDEFGH > abcdefghAAAAAAAA

Even if I use sendkeys on another element, this still occurs. E.g: send Abcdef on element1, then on element2 sends GHIJKabc, the text on element2 will be AAAAAabc

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
nhhaicommented, Nov 15, 2019

I tried this on a windows element (e.g: the text box in Run windows), and it doesn’t happen. This probably is a bug with Qt framework, I’ll debug to find out the problem.

For people who may also encounter this, my work around is to copy the text into clipboard and send ctrl + v (paste) instead.

Java code:

StringSelection selection = new StringSelection(value.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
e.sendKeys(Keys.CONTROL + "v" + Keys.CONTROL);
0reactions
faragmcommented, Jul 18, 2022

The copy to clipboard workaround works very well when running on same machine.

For remote execution I came up with the following workaround which seems to work fine.

  1. Replace any uppercase character with SHIFT+[the lowercase character]
  2. After any special character type a dummy special character while pressing SHIFT then delete it afterwards (This is not needed for all special characters but only those that requires pressing shift before but for simplicity I added for any special char )
public void type(String text) {
       StringBuilder modifiedText = new StringBuilder();
       for (int i = 0; i < text.length(); i++) {
           char ch = text.charAt(i);
           if (Character.isUpperCase(ch)) { 
               modifiedText.append(Keys.chord(Keys.SHIFT, Character.toString(Character.toLowerCase(ch))));
           } else if (!Character.isLetterOrDigit(ch)) { 
               modifiedText.append(ch);
               modifiedText.append(Keys.chord(Keys.SHIFT, "#", Keys.BACK_SPACE));
           } else {
               modifiedText.append(ch);
           }
       }
       element.sendKeys(modifiedText.toString());
   }
Read more comments on GitHub >

github_iconTop Results From Across the Web

'sendKeys' are not working in Selenium WebDriver
Make sure element is in focus → try to click it first and enter a string. · If there is some animation for...
Read more >
Selenium - sendKeys() not inserting value into textbox
If sendkeys() methods are not working then use following two ways to input text: Before sendkeys() use click() method to click inside ...
Read more >
sendKeys() not working in Selenium Webdriver
If we encounter issues while working with the sendKeys method, then we can use the JavaScript Executor to input text within an edit...
Read more >
SendKeys Is Not Working In Windows 10
I am creating a program in Visual Studio with C#. I want to send some keystrokes to another application running on my same...
Read more >
Solution for sendkeys(CharSequence) in Selenium
1- Right click on project. SendKeys is not working in Selenium · 2- Click on Java Compiler to 1.5 or later. sendkey issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found