Search code examples
javaseleniumselenium-webdriverawtrobot

Selenium Actions or Java AWT Robot?


Until now I have used the Selenium Actions library in order to perform mouse/keyboard actions in our automation project.

Recently, I have discovered the Java AWT Robot class. How is it comparable to Selenium Actions library? Is there some corner-cases in one of them that the other solve? restrictions? stability? performance considerations?


Solution

  • There is a huge difference in terms of how do these tools work. Selenium uses the WebDriver API and sends commands to a browser to perform actions (through the "JSON wire protocol").

    Java AWT Robot uses native system events to control the mouse and keyboard.

    If you are doing browser automation, ideally, you don't ever use things like Robot since usually the functionality provided by selenium is more than enough. Though, there are cases when there is a browser or native OS popup opened, for example, to upload/download a file - this is something that can be also solved with Robot - though usually there are selenium-specific solutions/workarounds that can help avoiding using Robot. The key idea of these workarounds is "since we cannot control the popups, just don't let them to be opened".

    For example, when you download a file in Firefox, you are getting a file browser popup suggesting you to choose a location and filename. This is something you cannot manipulate with using selenium. But, what you can do , is let Firefox know which file types and where do you want to save downloads automatically, without showing the popup. See Access to file download dialog in Firefox.

    Related topics: