Search code examples
javaseleniumawtrobot

AWT ROBOT - I can't find an element


I'm creating a application with WebDriver API for make non regression tests.

At a moment, I have to find an element (fic) on my computer (with the Windows's navigator), and i can't (or I just fail :P) do this with WebDriver.

So I'm searching for and I've find awt.Robot . But this robot just click on a [px,px] position.. How can I say 'Click on the search bar, click on the element with the name "A", click on the "OK" button ?' (All of these elements are Windows's elements.) Thank you for help !


Solution

  • The solution (for me) is to use this exemple to get the position+dimension of the window by its name.

    int[0] = X
    int[1] = Y
    int[2] = width
    int[3] = height

    In a second time, I use the awt.Robot with moveMouse() at the good position and click() or place the good characters.

    For the '/' slash, I use :

    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_COLON);
    robot.keyRelease(KeyEvent.VK_COLON);
    robot.keyRelease(KeyEvent.VK_SHIFT);

    I hope this helps someone.