Action vs Robot Class
đąď¸ Selenium Actions Class
Scope: Operates within the browser, sending commands via WebDriverâs API.
Purpose: Simulate highâlevel user gestures like click, hover, dragâandâdrop, and keyboard inputâbut only on web elements found in the DOM.
How it works: Sends âvirtualâ events to the browser driver, which then fires JavaScript or browser-level events.
Use Cases: Web-only interactions:
Hover menus
Double-clicks
Key sequences like Ctrl+C
Drag and drop
Actions actions = new Actions(driver); actions.moveToElement(menu) .click() .sendKeys("Hello") .perform();đ§âđť Java
RobotClassScope: Operates at the operating system level, controlling the real mouse and keyboard hardware.
Purpose: Automate tasks outside the browser, including system dialogs, file upload windows, or desktop apps.
How it works: Generates real native OS input eventsâe.g., moving the actual mouse cursor or sending keystrokes directly to the operating system.
Use Cases: Desktop-level actions:
OS file upload/download dialogs
Authentication pop-ups
Installing apps or interacting with native UI
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.mouseMove(500, 300);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
đ Comparison Table
| Feature | Actions Class | Robot Class |
| Level | Browser-level (WebDriver API) | OS-level (real mouse & keyboard) |
| Targets | Web elements (DOM only) | Any UI element (browser, OS dialogs, apps) |
| Interaction | Virtual events in browser context | Physical inputâmoves cursor, presses keys |
| Use cases | Hover, dragâdrop, key sequences, etc. | File uploads, OS dialogs, desktop apps |
| Cross-browser | Yes (WebDriver proxy) | Platform-dependent (screen resolution etc.) |
đ Key Takeaway
Use Actions when interacting with web elements inside the browser. Use Robot when you need to handle system-level dialogs or desktop interactions that Selenium can't reach.