We can perform all kinds of mouse and keyboard events in selenium webdriver using Actions interface.
Please note that we need to import below classes/interfaces to perform below operations.
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
package temp;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
@SuppressWarnings("unused")
public class OpenGoogle {
public static void main(String [] arg)
{
System.setProperty("webdriver.chrome.driver", "C:\\SelenuimProject\\chromedriver2.8.exe");
WebDriver driver = new ChromeDriver();
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
Hi Sagar
ReplyDeleteYour blog really helped me
Thanks
Hello Sagar
ReplyDeleteYour blogs are of gr8 help .
Thank you !
Really a very nice explanation.. thanks for your help
ReplyDeleteNice one and Can we have same one for mobile automation...
ReplyDelete