New data from 1,500+ QA pros: The 2025 State of Software Quality Report is live
DOWNLOAD YOUR COPY
All All News Products Insights AI DevOps and CI/CD Community

Selenium Click Command: How To Use It

Learn how to use the Selenium Click command to locate elements and perform user-like clicks with clear examples.

Hero Banner
Blog / /
Selenium Click Command: How To Use It

Selenium Click Command: How To Use It

QA Consultant Updated on

The Selenium click command is a built-in method used to simulate a user click on any element in a browser. It’s one of the most common actions in Selenium automation testing.

Whenever you automate a test, you’re always using some variation of the click command. It’s simple, powerful, and essential for testing user interfaces.

In this guide, we’ll cover:

  • What is the Selenium click command?
  • How to use it correctly in real test scenarios
  • Different click methods like right-click, double-click, and advanced clicks
  • How Katalon simplifies Selenium click automation

Let’s get started!

What is the Selenium click command?

The Selenium click command is a built-in method in the WebDriver interface. It tells the browser to simulate a real user click on a web element. This is how testers automate actions like clicking buttons, opening links, or submitting forms.

You’ll find it in almost every Selenium test script. Whether you're validating navigation flows or triggering JavaScript events, the click method is what makes that interaction happen.

Example of Selenium click command

When a user clicks a “Sign In” button, you want Selenium to do the same in your test. The click command sends that instruction to the browser just like a person would.

The method belongs to the WebElement interface. You locate the element first, then perform click() on it. This keeps your tests clear and focused on what users actually do.

The Selenium click command is one of the most frequently used methods in Selenium automation testing. It works because it mirrors user behavior, which makes it essential for UI and UX validation.

This method plays a key role in test coverage. If a user can interact with it, you can test it using click().

How to use Selenium click command?

The Selenium click() command is simple to use. First, locate the target element on the page. Then call the click() method on that element. This simulates an actual user click.

You can locate elements in several ways. Selenium supports:

  • IDBy.id("submitBtn")
  • NameBy.name("email")
  • CSS SelectorBy.cssSelector(".btn-primary")
  • XPathBy.xpath("//button[text()='Submit']")

Once you’ve identified the element, invoke click() to perform the action. Below are examples in both Java and Python.

Java
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");
WebElement signInButton = driver.findElement(By.id("sign-in"));
signInButton.click();

Python
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://katalon.com")
sign_in_button = driver.find_element(By.ID, "sign-in")
sign_in_button.click()

How to perform a right click in Selenium?

To simulate a right-click in Selenium, we use the Actions class. This class helps perform advanced user interactions like hover, drag, and right-clicks.

Right-clicking is useful for testing context menus, download options, or hidden file settings. When you trigger a right-click using Selenium, it opens the context menu just like a real user would do on a file or a button.

Here’s how you perform a right-click using Selenium in Java:

Java
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");

Actions actions = new Actions(driver);
WebElement fileIcon = driver.findElement(By.id("file-icon"));
actions.contextClick(fileIcon).perform();

This script opens the Katalon website, locates an element, and performs a right-click. The context menu appears just like it would if you right-clicked it manually.

You might use this for testing file downloads, action menus, or element-specific settings. Right-click interactions add flexibility to your Selenium click command usage.

If the context menu is dynamic, you can use WebDriverWait to ensure it's visible before selecting any options. Also, verify each menu item by checking their presence and text before interacting.

Right-click support makes your test suite more complete. It mirrors how users interact with advanced UI patterns, especially on modern web apps.

How to Perform a Left Click in Selenium?

The left click is the default behavior of the Selenium click() method. It works on any element that can receive a standard mouse click, such as buttons, links, checkboxes, and more.

This is the simplest form of the Selenium click command. You locate the element, then applyclick(). Here’s how that looks in Java:

Java
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");

WebElement startButton = driver.findElement(By.cssSelector(".start-btn"));
startButton.click();

Sometimes, a standard click may not register if the element is hidden by an overlay or triggered by JavaScript events. In these cases, the Actions class provides a more reliable way to click.

Here’s how to perform a left click using the Actions class:

Java
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");

WebElement element = driver.findElement(By.id("cta-button"));
Actions actions = new Actions(driver);
actions.click(element).perform();

The Actions-based click gives you better control. Use it when the element requires hover, has a visual transition, or sits behind an animation layer.

If the click doesn’t go through, check the timing. Add WebDriverWait to wait for the element to be clickable before performing the action.

Both click types are useful:

  • The regular click() keeps your code clean.
  • The Actions class adds flexibility when elements need more interaction before they respond.

Performing a Double Click in Selenium

A double click is different from a single click. In user scenarios, a double click selects text, opens folders, or triggers special functions. It simulates a quick repeated action on the same element.

Selenium supports double clicks using the Actions class. This lets you interact with elements that expect this specific input. Web apps that mimic file systems often use double click to open folders or files.

Here’s how to perform a double click in Selenium:

Java
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");

WebElement folderIcon = driver.findElement(By.className("folder-item"));
Actions actions = new Actions(driver);
actions.doubleClick(folderIcon).perform();

Use double clicks when you want to verify special behaviors. That includes selecting text in a form, opening an expandable section, or simulating a file explorer experience.

For consistent results, always make sure the element is visible and ready. You can add WebDriverWait to handle timing correctly. This keeps your test reliable, especially when the double click triggers async UI changes.

Advanced Click Techniques: Context Menu and Keyboard Events

The Selenium click command supports more than standard clicks. Advanced scenarios let you combine click actions with context menus, keyboard inputs, and hidden elements.

For example, after a right-click, you may want to select an option from a context menu. Use Actions to perform both steps.

Another pattern is multi-select. Use KeyDown to hold a key like Shift or Ctrl, then click elements to create a selection.

Here is a sample to combine click with Shift key:

Java
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");

Actions actions = new Actions(driver);
WebElement first = driver.findElement(By.id("item-1"));
WebElement second = driver.findElement(By.id("item-2"));

actions.keyDown(Keys.SHIFT).click(first).click(second).keyUp(Keys.SHIFT).perform();

Use this pattern to simulate selection in lists, file grids, or table rows. It improves your coverage for apps with rich UI behavior.

You can also click inside an iframe. Switch to the iframe first. Then find the target element and apply the Selenium click command.

If the target is inside a shadow DOM, use JavaScriptExecutor to access it. Selenium WebDriver does not directly handle shadow roots, but you can still interact with elements using scripts.

For all of these, timing is key. Always wait for the element to be interactable. Use WebDriverWait before applying advanced click logic. This ensures your test behaves like a user, even in dynamic UI flows.

These advanced techniques help simulate real user actions with accuracy. They expand what you can test and how deeply you can validate user experiences.

Why use Katalon for Selenium testing?

Katalon logo

Katalon is a complete automation platform built on top of Selenium and Appium. It adds a powerful keyword-driven engine to simplify test creation, especially for click commands and browser actions. With Katalon, you can run complex UI interactions without deep coding knowledge.

Instead of writing raw Selenium code, you can use a single keyword like WebUI.click(findTestObject("ObjectName"). This keeps your test scripts easy to read, easy to maintain, and ready for scale.

Here are some of the key benefits of using Katalon for Selenium testing:

  • Keyword-driven simplicity: Use built-in keywords to interact with UI elements quickly and reliably. Scripts stay clean even as your test suite grows.
  • Fast-start learning resource: The free Using Built-in Keywords in Katalon course teaches you how to build tests using test objects and reusable keywords.
  • Official reference for click behavior: The Katalon WebUI.click() docs explain how Katalon automatically retries click actions when overlays are present.
  • Object Repository Integration: All UI elements are stored in one place. You can reuse them across multiple test cases without writing locators from scratch.
  • Cross-browser and mobile support: You can run your click tests across Chrome, Firefox, Safari, Edge, Android, and iOS using the same test logic.
  • Low-code test authoring: In Manual Mode, you build tests using drag-and-drop. Then switch to Script Mode for more control when needed.
  • Expandable via custom keywords: Create your own keywords when your use case needs a tailored action or extra logic.
  • Robust debugging and maintainability: Every test run includes screenshots, logs, and execution history to speed up your troubleshooting.
  • CI/CD & reporting integration: Plug Katalon into Jenkins, GitHub Actions, or any CI pipeline. Reports are automatically generated after each run.

Katalon builds on Selenium’s power but removes the boilerplate. With keyword-driven syntax, built-in object handling, free Academy training, and easy cross-platform support, you spend less time wrestling with setup and more time delivering quality tests.

Ask ChatGPT
|
Vincent N.
Vincent N.
QA Consultant
Vincent Nguyen is a QA consultant with in-depth domain knowledge in QA, software testing, and DevOps. He has 10+ years of experience in crafting content that resonate with techies at all levels. His interests span from writing, technology, building cool stuff, to music.
on this page
Click