PAGE 14 : HOW TO DOUBLE CLICK ON THE WEB ELEMENT IN SELENIUM WEBDRIVER

EXAMPLE:
package com.keysCommands;

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.Action;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;


public class DoubleClickExample {

@Test
public void doubleclickTest(){
WebDriver driver = new FirefoxDriver();

try {
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS);

driver.get("http://www.google.com/");

Thread.sleep(3000);

WebElement element = driver.findElement(By.id("hplogo"));

Actions builder = new Actions(driver);

// build the action chain.
Action doubleclick = builder.doubleClick(element).build();

// perform the double click action
doubleclick.perform();

Thread.sleep(8000);

}

catch (Exception e) {
System.out.println("Exception - > " + e.toString());
} finally {
driver.close();
driver.quit();
}
} // main function ends

}// class ends


Executing test via TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<suite name="DoubleClickExample in Selenium WebDriver">
<test name="DoubleClickExample Test">
<classes>
<class name="com.keysCommands.DoubleClickExample" />
</classes>
</test>


</suite>



No comments:

About Me

My photo
Pune, Maharastra, India
You can reach me out at : jimmiamrit@gmail.com