Different way to sendkeys. (AutoIt)

autoit
java
rpa
selenium

#1

Hi All,

I came across a issue where the normal route of sendKeys did not work i.e. sDriver.getKeyboard().sendKeys(new String[]{"{UP}"});
In my case specifically the TAB key did not work. So I made use of the JAVA java.awt.Robot library and implemented it as per the following:

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(100);

This did the trick. One important note is I found that you need to instantiate the robot class after you have focus on the window that you want to use.

Hope this helps someone.


#2

Note: the code must be executed on the RPA machine (which is remote in most of the cases). Example how it can be done:
https://kb.workfusion.com/display/TR/Automating+Command+Line


#3

Just to clarify you will create a java class file and that you will execute on the agent in the command line.

Example:

<code>
String scriptResult = autoitDriver2.executeScript(
"import java.awt.Robot;\n"+
"import java.io.BufferedReader;\n"+
                    "import java.io.InputStreamReader;\n"+
                   
                    "String command = \"java -cp /rpa/java/bin RobotClass \";\n"+
                    "StringBuffer output = new StringBuffer();\n"+
                    "Process p;\n"+
                    "try {\n"+
                    "    p = Runtime.getRuntime().exec(command);\n"+
                    "    p.waitFor();\n"+
                    "    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));\n"+
                    "    String line = \"\";\n"+         
                    "    while ((line = reader.readLine())!= null) {\n"+
                    "        output.append(line + \"\\n\");\n"+
                    "    }\n"+
                    "} catch (Exception e) {\n"+
                    "    e.printStackTrace();\n"+
                    "}\n"+
                    "return output;", new String[]{"GROOVY"}).toString();</code>