package com.gloryroad.Demo;
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.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class MouseClickAndRelease {
String url="http://127.0.0.1:8020/HTMLDemo/HTMLPDir/Temp02/moveAndClick.html";
public WebDriver driver;
@BeforeMethod
public void setUp(){
driver=new FirefoxDriver();
driver.get(url);
}
@AfterMethod
public void tearDown(){
driver.close();
}
@Test
public void clickAndRelease(){
WebElement div=driver.findElement(By.xpath("//div[@id='div1']"));
Actions act=new Actions(driver);
act.clickAndHold(div);
try {
Thread.sleep(3000);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
act.release(div).perform();
try {
Thread.sleep(3000);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
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.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class MouseClickAndRelease {
String url="http://127.0.0.1:8020/HTMLDemo/HTMLPDir/Temp02/moveAndClick.html";
public WebDriver driver;
@BeforeMethod
public void setUp(){
driver=new FirefoxDriver();
driver.get(url);
}
@AfterMethod
public void tearDown(){
driver.close();
}
@Test
public void clickAndRelease(){
WebElement div=driver.findElement(By.xpath("//div[@id='div1']"));
Actions act=new Actions(driver);
act.clickAndHold(div);
try {
Thread.sleep(3000);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
act.release(div).perform();
try {
Thread.sleep(3000);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}