0

I am working on an automated test that needs to open a document in Internet Explorer. The script works perfectly fine until after clicking a link to the document, which launches the pesky IE popup window like below

enter image description here

Since I am not able to focus on the window using Webdriver, I have tried to use Robot.java to send the keys "Alt+O", which works fine manually, but deadlocks at runtime while executing. My assumption is there is some incompatibility with Selenium/Robot.java but I'm stumped on this one as I am not able to generate any logs due to the deadlock. Please do not suggest using AutoIT as my security analysts will not let me use it for some silly reason. Any help is much appreciated.

Tooling:

  1. selenium-server-standalone-2.41.0
  2. IEDriverServer (32 bit version)
  3. Internet Explorer version = 9
  4. Script is written in Java

MyRobot.java

public class MyRobot {

private static Robot robot;

public static void sendVirtualKeyCombination(int... keyEvents) {

    try {

        robot = new Robot();
        robot.setAutoDelay(1000);

        // Press key combination
        for (int keyEvent : keyEvents) {
            System.out.println("Pressing " + KeyEvent.getKeyText(keyEvent));
            robot.keyPress(keyEvent);
        }

    } catch (AWTException e) {
        e.printStackTrace();
    } finally {

        // Release all keys
        for (int keyEvent : keyEvents) {
            System.out.println("Releasing " + KeyEvent.getKeyText(keyEvent));
            robot.keyRelease(keyEvent);
        }
    }

}
}

MyRobot invocation

MyRobot.sendVirtualKeyCombination(KeyEvent.VK_Alt, KeyEvent.VK_O);
eltabo
  • 3,749
  • 1
  • 21
  • 33
Jason
  • 1,371
  • 4
  • 21
  • 44
  • Have you tried doing a delay instead of sleep? For example = robot.delay(50); – qaRookie Jul 08 '14 at 21:49
  • @seleniumRookie Like I'm going to take advice from a seleniumRookie! just kidding... I'll give that a try tomorrow and let you know how it goes. Thanks. – Jason Jul 08 '14 at 23:58

2 Answers2

0

Try releasing the key half a second after the key press. the error may be due to very little delay between pressing and releasing the key.

// Press key combination
for (int keyEvent : keyEvents) {
    System.out.println("Pressing " + KeyEvent.getKeyText(keyEvent));
    robot.keyPress(keyEvent);
    }

    thread.sleep(500)

for (int keyEvent : keyEvents) {
    System.out.println("Releasing " + KeyEvent.getKeyText(keyEvent));
    robot.keyRelease(keyEvent);
    }
Lone Ronin
  • 2,530
  • 1
  • 19
  • 31
0

I faced the same issue in Firefox . Try using threads . Start two threads , first one for opening the pop up button . Now things freeze . Now, put some wait in second thread and perform sends keys.

Hope this works .

Siv
  • 37
  • 1
  • 9