The Basic click() and Click Interception
WebElement.click() simulates a mouse click at the element's center point, but WebDriver first checks that the element is visible, enabled, and not obscured by another element. If a different element — such as a fixed header, a modal overlay, or a cookie-consent banner — currently occupies that same screen position, WebDriver throws ElementClickInterceptedException rather than silently clicking the wrong thing. This is a deliberate safety behavior: a real user couldn't click through an overlay either, so Selenium refuses to fake that interaction.
Cricket analogy: A plain click() is like a fielder diving for a catch only to find another fielder already converged on the same ball — ElementClickInterceptedException is Selenium's way of saying another element, like an overlay, got there first and blocked the catch.
The Actions Class: Hover, Click-and-Hold, Double-Click
The Actions class builds a chain of low-level mouse and keyboard events for interactions click() alone can't express. moveToElement(element) hovers the mouse over an element, useful for revealing CSS :hover-triggered menus before the target item becomes clickable. clickAndHold(element) presses the mouse button down without releasing, paired later with release() — useful for drag operations or UI that responds to a sustained press duration. doubleClick(element) fires two rapid clicks, distinct from two separate click() calls because the browser's dblclick event only fires when the clicks happen within its native timing threshold.
Cricket analogy: Actions.moveToElement() to reveal a hover menu is like a batsman shuffling in the crease to draw the bowler's field to shift before playing the actual shot — the hover changes what becomes visible or clickable next.
Keyboard Actions and Key Combinations
Simple key presses like Enter can be sent directly with sendKeys(Keys.ENTER) on a focused element. For modifier-key combinations like Ctrl+A (select all) or Shift+Click, the Actions class provides keyDown(key) and keyUp(key), which press and release a modifier while it overlaps with another action in between — this is essential because sendKeys(Keys.chord(Keys.CONTROL, "a")) or the explicit keyDown/sendKeys/keyUp sequence ensures the modifier is actually held down at the moment the other key is pressed, matching how a real keyboard combination works.
Cricket analogy: Sending Keys.ENTER after typing in a search box is like a bowler completing their run-up and releasing the ball — it's the natural terminating action, distinct from clicking a separate 'submit' button like the umpire raising a finger.
// Basic click
driver.findElement(By.id("checkout-btn")).click();
// Hover to reveal a dropdown menu, then click a submenu item
Actions actions = new Actions(driver);
WebElement menu = driver.findElement(By.id("account-menu"));
actions.moveToElement(menu).perform();
WebElement logoutLink = driver.findElement(By.linkText("Logout"));
actions.moveToElement(logoutLink).click().perform();
// Click and hold for a slider drag
WebElement handle = driver.findElement(By.id("volume-handle"));
actions.clickAndHold(handle)
.moveByOffset(50, 0)
.release()
.perform();
// Ctrl+A to select all text in a field, then delete
WebElement editor = driver.findElement(By.id("editor"));
actions.click(editor)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.sendKeys(Keys.DELETE)
.perform();ElementClickInterceptedException often means a sticky header, cookie banner, or animating modal is covering the target. Don't reach for JavaScriptExecutor clicks to force through this — first fix the real blocker (dismiss the banner, wait for the animation to finish) since a forced JS click can mask a bug a real user would also hit.
Every Actions chain requires a final perform() call — building the chain with moveToElement().click() etc. queues the actions but does nothing until perform() executes them against the browser.
- click() throws ElementClickInterceptedException if another element currently occupies the same screen position.
- The Actions class enables hover (moveToElement), sustained press (clickAndHold/release), and doubleClick.
- Actions chains must end with perform() or nothing happens.
- sendKeys(Keys.ENTER) sends a single key press to a focused element.
- Modifier combinations like Ctrl+A require keyDown/keyUp pairs (or Keys.chord) so the modifier overlaps the other key press.
- Don't paper over ElementClickInterceptedException with a forced JS click — fix the actual overlay/blocker.
Practice what you learned
1. What does WebDriver do if a click target is covered by another element, such as a modal overlay?
2. What is required at the end of every Actions class chain for the actions to actually execute?
3. Why is a keyDown/keyUp pair needed to simulate Ctrl+A rather than two separate sendKeys() calls?
4. What does Actions.clickAndHold(element) do?
5. What is the recommended response when a test hits ElementClickInterceptedException?
Was this page helpful?
You May Also Like
Interacting with Forms and Inputs
How to type into text fields, clear stale values, submit forms, and upload files with Selenium's WebElement API.
Handling Dropdowns and Checkboxes
How to work with native <select> dropdowns via the Select class, and correctly toggle checkboxes and radio buttons.
Waits: Implicit, Explicit, and Fluent
How Selenium's three wait strategies — implicit, explicit, and fluent — handle timing and synchronization with a dynamic page.