1.

Explain methods to implement the Robot class in Selenium?

Answer»

Below are the few methods that help in the easy execution of test scripts required for Robot class implementation.

  1. KEYPRESS()
  2. KeyRelease()
  3. MouseMove()
  4. MousePress()
  5. MouseRelease()

Let us understand these methods in details -

  1. KeyPress() - Use this METHOD when you want to PRESS any KEY

Example : robot.keyPress(keyEvent.VK_UP); will press UP key on the keyboard.

  1. KeyRelease() - Use this method to release the pressed key on the keyboard.

Example: robot.keyRelease(keyEvent.VK_CAPS_LOCK); will release the pressed caps lock key on the keyboard.

  1. MouseMove() - use this method when you want to move the MOUSE pointer in the X and Y coordinates.

Example : robot.mouseMove(coordinates.get.X(),coordinates.get.Y());will move the mouse over X and Y coordinates.

  1. MousePress() - use this method to press the left button of the mouse.

Example - robot.mousePress(InputEvent.BUTTON1_MASK); will press the mouse button

  1. MouseRelease() - Help this method in releasing the pressed button of the mouse.

Example - robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK); will release the right click of the mouse.

Let us see the code on how to declare robot class -

Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_DOWN); //will press down key on the keyboard robot.keyPress(KeyEvent.VK_TAB); // will press tab key on the keyboar


Discussion

No Comment Found