We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Simulating a real mouse click on the center of an element in Selenium.
The click() command tells the browser to simulate a real mouse click on a web element. It’s one of the most common interaction commands in Selenium and is used almost everywhere.
click() tries to behave like a real user. If the center point is covered or the element isn’t interactable, Selenium throws an exception instead of faking the click.Element ID: lesson3-click-me
State: Ready
Click the button and observe the state change. This confirms the click was successful and the UI responded.
1234WebElement clickMeButton = driver.findElement(By.id("lesson3-click-me"));
clickMeButton.click();
driver.quit();id. Using id is usually the most stable and reliable locator.WebElement reference so you can reuse it for multiple interactions if needed.Never assume a click worked just because no exception was thrown. Always verify a side effect: Did the state text change? Did the page navigate? Did a new element appear?
Remember: click() targets the center of the element. If that center is covered by an overlay, modal, or sticky header, you can get an ElementClickInterceptedException.