Tuesday 9 February 2016

How to perform double click operation in selenium webdriver

How to perform double click operation in selenium webdriver:
==============================================
By using Actions class we can perform double click operations.
This actions class is having one non static method called doubleClick() and this method always ask you tthe webelement on which you want to perform the double click operation.

public Actions doubleClick(WebElement element);
-----------------------------------------------------------------

//sample example on how to perform doubleClick
-------------------------------------------------------------
package blog;

import java.util.concurrent.TimeUnit;

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;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class DoubleClickDemo {

WebDriver driver;
Actions actions;

String expectedTitle = "jQuery UI";

@BeforeSuite
public void openBrowser() {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

}

@AfterSuite
public void closeBrowser() {
if (driver!=null) {
driver.quit();
}

}
@Test
public void testScript() {
driver.get("https://www.jqueryui.com");

String actualTitle = driver.getTitle();
if (actualTitle.equalsIgnoreCase(expectedTitle))
{

WebElement element = driver.findElement(By.linkText("Autocomplete"));
actions = new Actions(driver);

actions.doubleClick(element).click().build().perform();


}

}

}

No comments:

Post a Comment