# 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
    
* ```bash
    Actions actions = new Actions(driver);
    actions.moveToElement(menu)
           .click()
           .sendKeys("Hello")
           .perform();
    ```
    
    ## 🧑‍💻 Java `Robot` Class
    
    * **Scope:** 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
            
    

```bash
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.
