How To Perform Double Click Action In Selenium WebDriver
Perform Double Click Action In Selenium:
In some scenarios, we may need to do double click action on a particular element to move further. In such cases, we use Actions class in Selenium WebDriver to work on Mouse and Keyboard Actions. Check out the below link for detailed explanation of Actions Class.
Must Read:Â Actions Class in Selenium WebDriver
Scenario to be automated:
- Launch the web browser and open the application
- Find the required element and do double click on the element
- Close the browser to end the program
Copy the below mentioned script and work on this scenario.
Given clear explanation in the comments section with in the program itself. Please go through it to understand the flow.
package softwareTestingMaterial; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; import org.testng.annotations.Test; public class ActionsClass { @Test public void doubleClick() throws InterruptedException{ System.setProperty("webdriver.chrome.driver", "D:\\Selenium Environment\\Drivers\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); //Open the required URL where you could do double click action driver.get("http://api.jquery.com/dblclick/"); //Maximize the browser driver.manage().window().maximize(); //As per the above URL we need to switch to frame. The targeted element is in the frame driver.switchTo().frame(0); //Create the object 'action' Actions action = new Actions(driver); //Find the targeted element WebElement ele = driver.findElement(By.cssSelector("html>body>div")); //Here I used JavascriptExecutor interface to scroll down to the targeted element ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", ele); //used doubleClick(element) method to do double click action action.doubleClick(ele).build().perform(); //Once clicked on the element, the color of element is changed to yellow color from blue color //driver.close(); } }
If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.
Hi Raj
need your help in simulating double click using Selenium Open2Test framework….
Pl let me know your contact number