DoubleClick
@Test
public void performDoubleClick() throws InterruptedException{
WebElement ele = driver.findElement(By.xpath("//button[contains(.,'Double-Click Me To See Alert')]"));
Actions act = new Actions(driver);
act.moveToElement(ele).perform();
act.doubleClick().perform();
Thread.sleep(5000);
Alert alert = driver.switchTo().alert();
alert.accept();
Thread.sleep(5000);
}
Switch Alert
Alert alert = driver.switchTo().alert();
alert.accept();
Thread.sleep(5000);
}
DragAndDrop
@Test
public void performDragAndDrop() throws InterruptedException{
WebElement iFrame = driver.findElement(By.className("demo-frame"));
driver.switchTo().frame(iFrame);
// Store the web elements
WebElement src = driver.findElement(By.id("draggable"));
WebElement dest = driver.findElement(By.id("droppable"));
Thread.sleep(2000);
Actions act = new Actions(driver);
act.dragAndDrop(src, dest).build().perform();
Thread.sleep(5000);
}
@Test
public void performDragAndDrop2() throws InterruptedException{
WebElement iFrame = driver.findElement(By.className("demo-frame"));
driver.switchTo().frame(iFrame);
// Store the web elements
WebElement src = driver.findElement(By.id("draggable"));
WebElement dest = driver.findElement(By.id("droppable"));
Thread.sleep(2000);
Actions act = new Actions(driver);
act.clickAndHold(src).moveToElement(dest).release().perform();
Thread.sleep(5000);
}
Keyboard Events
@Test
public void performDragAndDrop() throws InterruptedException{
WebElement text = driver.findElement(By.name("firstname"));
Actions builder = new Actions(driver);
builder.keyDown(Keys.SHIFT)
.sendKeys(text, "anshul")
.keyUp(Keys.SHIFT)
.build().perform();
Thread.sleep(5000);
}
Mouse Hovor
@Test
public void performMouseHover() throws InterruptedException{
WebElement seleniumLink = driver.findElement(By.xpath("//*[@id='menu-item-10548']/a"));
Actions act = new Actions(driver);
act.moveToElement(seleniumLink).perform();
Thread.sleep(5000);
WebElement webdriverLink = driver.findElement(By.xpath("//*[@id='menu-item-9383']/a"));
webdriverLink.click();
Thread.sleep(5000);
}
Right CLick
@Test
public void performRightClick() throws InterruptedException{
WebElement rightClick = driver.findElement(By.cssSelector(".context-menu-one.btn.btn-neutral"));
Actions act = new Actions(driver);
act.moveToElement(rightClick).perform();
act.contextClick().perform();
Thread.sleep(5000);
}