Robot Class in Selenium:

 

  • Using Robot Class we can handle keyboard and mouse events in Selenium.
  • Robot Class can help in upload / download files using selenium web driver.
  • Methods in Robot Class can be effectively used to do the interaction with popups in Web Applications.
  • Robot Class can easily integrated with current automation framework (keyword, data-driven or hybrid).

 

Robot Class Handle Below Options:

  • Press Escape key from keyboard using Different Robot class Methods.
  • Handle Mouse Buttons Using Robot class.
  • Scroll Mouse Using Robot class.
  • Screen Capture Using Robot class.

 

Package:

  • Using below packages we handle Robot Class Methods.

 

Creating Object of robot class in Selenium:

  • Create Instance / Object of Robot() Class to Use Methods.

 

Methods under Robot Class are:

  • .keyPress();
  • .mousePress();
  • .mouseMove();
  • .keyRelease();
  • .mouseRelease();

 

Press Escape key on keyboard using Different Robot class Methods:

 

  1. .keyPress()
  • Using keyPress() Method we Press any key from KeyBoard.

  1. .keyRelease()
  • Using keyRelease() Method we Release the Pressed any key from KeyBoard.

  1. .mousePress()
  • Using mousePress() Method we press Left mouse button from Mouse.

  1. .mouseRelease()
  • Using mouseRelease() Method we Release pressed Left mouse button from Mouse.

  1. .mouseMove()
  • Using mouseMove() Method use to Move cursor pointer to X and Y co-ordinates.

 

Note: keyPress will send an event that a key has been pressed down. keyRelease will send the event that the key has been released .

 

Steps to Press Escape key on keyboard Robot class:

  • Create object of Robot class.
  • Using keyPress method press Escape key from KeyBoard.
  • Using keyRelease method release the CAPS_LOCK key.
  • Using mousePress Method press Left mouse button.
  • Using mouseRelease Method release the Left mouse button.
  • Using getLocation() method Get Location and using mouseMove(coordinates.getX(), coordinates.getY() method move mouse on X,Y Co-Ordinate.

 

Example: Press Escape key on keyboard using Different Robot class Methods:

 

Example: Handle Mouse Buttons Using Robot class:

 

Example: Scroll Mouse Using Robot class: 

  • Scroll Mouse using mouseWheel() Method.

 

Example: Screen Capture Using Robot class: