Double click in Selenium:
- Double click involves clicking on your mouse button twice to make a double click, and not just two clicks, in a short time the mouse button should be pressed twice, usually around half a second.
- Used to do double-clicking to do different things, such as opening a program, opening a folder or choosing a word of text.
- It double click on the current mouse position.
Scenario’s to Perform Double Click on WebElement:
- in-Built doubleClick Method exist in Action Class.
- We Perform Double Click operation using Action Class.
- Create Instance / Object of Action class.
- findElement where we want perform Double Click operation.
- Store findElement into WebElement.
- Using in-Built doubleClick method perform Double Click operation on WebElement.
Double click on WebElement:
1 2 3 4 5 6 7 8 | // Create object of Action class Actions action = new Actions(driver); // Find element using locator and store into WebElement WebElement element = driver.findElement(By.id("elementId")); // Perform Double click operation using action (object) on element. action.doubleClick(element).perform(); |
Package import to Create a Instance of Action Class:
- After create instance of Action Class we handle multiple Methods such as clickAndHold(), contextClick(), doubleClick(), dragAndDrop(source, destination), keyDown(modifier_key), keyUp(modifier_key), moveToElement(destination_Element), release() etc…
1 | import org.openqa.selenium.interactions.Actions; |
Step’s to Perform Double Click on WebElement in Selenium using Java:
- setProperty of geckodriver to Launch Firefox Browser.
- Create a driver object to handle WebDriver Methods.
- Using driver.get Open URL in Browser.
- Create Instance / Object of Action Class to Perform Double Click Operation.
- Find WebElement where we want to Perform Double Click Operation.
- Perform doubleClick operation on WebElement using in-Built Method of Action Class.
Example to Perform Double click in Selenium:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; public class Mouse_Hover { public static void main(String[] args) { System.setProperty("webdriver.gecko.driver","D:\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.get("https://www.stqatools.com"); // Create object of Action class Actions action = new Actions(driver); // Find element using locator and store into WebElement WebElement element = driver.findElement(By.id("elementId")); // Perform Double click operation using action (object) on element. action.doubleClick(element).perform(); } } |
Double Click an element using Selenium WebDriver with Java and code to double click an element using selenium and check double click in selenium webdriver