0

I'm trying to build an automation script that will install a chrome extension.

On my local system (windows 10) all works fine while using Robot class with java, since I have a physical keyboard connected to my computer.

The problem is - when I try to run this automation on a virtual machine(Amazon EC2, windows server), the Robot class is not working because it doesn't detect a physical connection of a keyboard.

Is there any other way to simulate a keyboard stroke without a keyboard attached?

FYI, I have to use the keyboard because google install box is not part of the page and selenium wont recognize it.

I've tried the sendKeys function but it didn't work because it will affect only the webpage itself and not pop outside of the page

eric.itzhak
  • 15,752
  • 26
  • 89
  • 142
Pikolo
  • 99
  • 1
  • 3
  • 11
  • selenium is testing webpages. it "clicks" on buttons based on their id's. how would it be able to click on a keyboard? – Stultuske Jan 02 '18 at 09:23
  • Possible duplicate of [Send keys not working selenium webdriver python](https://stackoverflow.com/questions/46770697/send-keys-not-working-selenium-webdriver-python) – undetected Selenium Jan 02 '18 at 09:43
  • Can you show us your code trials and update where you are exactly stuck? – undetected Selenium Jan 02 '18 at 09:51
  • @Stultuske It's possible with Robot framework, that's what i said. – Pikolo Jan 02 '18 at 10:06
  • @DebanjanB The code is not that relevant... just imagine a new instance of Robot that try to click "left arrow" and then "Enter". on my local pc it works great, but on the vm it's not. – Pikolo Jan 02 '18 at 10:07
  • Leaving aside `Robot`, **`WebDriver`** can do each and everything. Show us your code trials and update where you are exactly stuck? – undetected Selenium Jan 02 '18 at 10:08
  • @DebanjanB after i'm using JS function chrome.webstore.install() chrome initiate the inline installation of the extension. then chrome pop up waiting for user interaction to click the "install" button. then i use the robot class to click Enter on the install like this: robot.keyPress(KeyEvent.VK_ENTER); and robot.keyRelease(KeyEvent.VK_ENTER); – Pikolo Jan 02 '18 at 13:01

2 Answers2

3

I believe you can use java robot functions to mimic the keyboard interactions.

Example:

package org.kodejava.example.awt;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class CreatingKeyboardEvent {
    public static void main(String[] args) {
        try {
            Robot robot = new Robot();

            // Create a three seconds delay.
            robot.delay(3000);

            // Generating key press event for writing the QWERTY letters
            robot.keyPress(KeyEvent.VK_Q);
            robot.keyPress(KeyEvent.VK_W);
            robot.keyPress(KeyEvent.VK_E);
            robot.keyPress(KeyEvent.VK_R);
            robot.keyPress(KeyEvent.VK_T);
            robot.keyPress(KeyEvent.VK_Y);
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
}
Vijendran Selvarajah
  • 1,330
  • 1
  • 11
  • 31
1

I don't think you can do this with Selenium, cause it is meant to test webpages, not to automate a human-computer interaction.

If you want to automate a complex scheme like this, you may try a more complete solution, like UiPath : https://www.uipath.com/

This is a solution meant for automation, so it will give you more tools to achieve your goal. It has a community edition which is free, and an active forum, so you should be able to handle it quickly !

Heratom
  • 35
  • 12
  • I'm looking for something that will be like a script... i don't want to install anything on the vm... this software needs to be installed on the computer – Pikolo Jan 02 '18 at 10:42
  • Indeed you'll have something to install on your VM, and eventhough you can limit the impact, you will at least need the browser plugin and the robot software... Sorry for not helping – Heratom Jan 03 '18 at 11:20