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:
Let’s get started!
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.
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().
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:
Once you’ve identified the element, invoke click() to perform the action. Below are examples in both Java and Python.
WebDriver driver = new ChromeDriver();
driver.get("https://katalon.com");
WebElement signInButton = driver.findElement(By.id("sign-in"));
signInButton.click();
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()
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:
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.
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:
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:
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:
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:
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.
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:
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.
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:
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.