The Selenium Click Command (Including Examples)

Sauce AI for Test Authoring: Move from intent to performance in minutes.|xBack to ResourcesBlogPosted<

June 03, 2026 · 4 min read · Tool Comparison

Sauce AI for Test Authoring: Move from intent to performance in minutes.

|

x

Back to Resources

Blog

Posted April 1, 2023

The Selenium Click Command (Including Examples)

Learn how Selenium ’ s click () dictation work to simulate shiner click for automated UI testing, as well as how to send a right-click mouse command.

Documentation

If you ’ re using to automateUI testingfor your app,Selenium ’ s click () dictationwill become one of your almost commonly use method. It ’ s important to understand how the Seleniumclick()bidding works for and how to bump more information and resources when your need are more complex.

What is the Selenium Click Command?

Selenium ’ sclick()bidding emulate a mouse click operation for any interactional UI constituent (tie-in, buttons, checkboxes, radio buttons). Simulating shiner clicks using Selenium can not only save crucial manual testing effort, but also aid to identify bugs in your coating.

How to Use the Selenium Click Command

Here ’ s an example of the Seleniumclick() command:

The next Java command conjuration simulates a click on a push (with the HTML ID “ clickable ”)

clickable = driver.findElement (By.id (& quot; clickable & quot;));
clickable.click ()

Form submissions and buttons are the most common drivers of “ state change ” in an application, and they tend to be the most important steps in any test. It ’ s after the click that the assertions need to be make, to analyze the resulting page changes for actual-vs-expected conduct.

However, the Seleniumclick()command only extend the left shiner button, the near common kind of mouse interaction. What happens when you involve to click with the right shiner push?

Advanced Click Techniques: Sending a Right-Click Mouse Event

Sometimes you & # x27; ll run into an app that has functionality hidden behind a right-click menu (e.g., a context card). These lean to be system-level menus that are untouchable by Selenium ’ s nonpayment methods. So how do you get to them?

By leveragingSelenium ’ s shiner activity library, you can publish a right-click bidding (a.k.a. acontext_click).

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

Let & # x27; s use a right-click example fromthe-internet:

The Internet JavaScript Selenium Click Event Example

This page will render a custom context menu when we right-click ona specific region of the page. For instance:

Selenium Click Event Test Example

Clicking the context menu will trigger a JavaScript alert that says,” You selected a context card. ”

driver.navigate ()
.to (& quot; http: //the-internet.herokuapp.com/context_menu & quot;);
WebElement clickable =
driver.findElement (By.id (& quot; hot-spot & quot;));
new Actions (driver)
.contextClick (clickable)
.perform ();
Alert alarm = new WebDriverWait (driver,
Duration.ofSeconds (2))
.until (ExpectedConditions.alertIsPresent ());
Assertions.assertEquals (& quot; You selected a context carte & quot;,
alert.getText ());

First, navigate to the page and regain your right-clickable element. Once you have it, send the actions-basedcontextClick (). After you direct the case, wait for an alert to appear, then affirm that the schoolbook message appear as look.

By following this example and looking atSelenium ’ s Actions API documentation, you should be able to mail mouse actions like clink,double-click, right-click,click-and-hold, back-click, and more. In addition to standard mouse events, the Selenium Actions API also provides support formouse wheel, pen activeness, and just about anything you ’ d want to do with akeyboard.

Getting Started with the Selenium Click Command

These examples have shown the basics of how to send shiner event. In your own test codification, be certain to abstract out complicated code like actions when you ’ re act with common web elements, so that tester encountering your code in the future can get changes apace. There are many ways to sham various shiner events, and this article didn ’ t touch on any more than the basics. Be sure to check outthe official Selenium documentationfor more point.

Ready to start testing with Selenium and Sauce Labs?

Let & # x27; s go!

LinkedIn
© 2026 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered hallmark have by Sauce Labs Inc. in the United States, EU, and may be registered in early jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free