Today I learned a new topic called Robot Class and thought to share with you all.
Why Robot class?
We use this to control keyboard or mouse actions in OS windows like downloading, uploading, pop-up, alerts, print Pop-ups etc.
Why we need Robot class?
When we have to do any action in Webpage, we need a locator to perform the action. However, in OS windows we don’t have any locators to overcome this situation so we use Robot Class.
Benefits of Robot Class?
· Handles keyboard and mouse actions
· It helps in uploading/ downloading of files using selenium web driver
· It helps in managing pop-ups, alerts etc.
Common keys used in Robot Class are:
Down arrow key- robot.keyPress(KeyEvent.VK_DOWN)
Tab Key- robot.keyPress(KeyEvent.VK_TAB)
Enter Key-robot.keyPress(KeyEvent.VK_ENTER)
How to use Robot Class?
1st Step:
Instantiate the Robot class.
Robot robot = new Robot();
2nd Step:
Import Robot
3rd Step:
Give action which you required. Example given Below
robot.keyPress(KeyEvent.VK_DOWN);
4th Step:
Import the KeyEvent
Comments