Selenium: mouse and keyboard actions, dropdowns and file upload
Some page controls need more than a click. Learn how to use the Actions API, pick from a dropdown and upload a file in a Selenium test.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a snack machine. Some machines need only a button press. Others need you to hold a key, choose a row and drop in a coin, in the right order.
The machine does nothing until all the steps are done.
The builds those steps. Tom, the tester at Daily List, a to-do list app, uses it for controls that need more than a click. The skill is to pick the right tool for each control and then wait for the result.
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB A snack machine that needs a few steps in order.
- Build
- Perform
- Wait
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| Holding a key | Pressing a key down |
| Choosing a row | Picking a dropdown option |
| Dropping a coin | Sending the file path |
| Waiting for the snack | Waiting for the result |
WHERE THIS PICTURE STOPS
- A machine has fixed buttons, but a page control can be custom built.
- A coin is real, but a file path is only text.
- A machine gives a snack, but a test checks the page.
HOOK
Chain the steps, then wait.
TELL A FRIEND
A snack machine: do the steps in order, then wait.
OFTEN MIXED UP WITH Selenium WebDriver: your first small suite. That topic builds the first Selenium suite. This one handles controls that need more than a click.
PRACTISE AND KEEP
Sources for this topic — 3 sources
- Market practice
Interacting with web elements (Selenium documentation) ↗ — Selenium · Selenium documentation: the basic element commands are click, send keys, clear, submit and select, and each applies only to some element types (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
File upload (Selenium documentation) ↗ — Selenium · Selenium documentation: a test cannot drive the native file dialog, so it sends the full file path to the file input and then submits (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Mouse actions (Selenium documentation) ↗ — Selenium · Selenium documentation: the Actions API builds mouse actions such as hover and drag and drop, and runs them with a perform call (search excerpt, page not opened)
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.