71. What is actions
class in web driver?
Actions class with web
Driver help is Sliding element, Resizing an Element, Drag & Drop
Hovering a mouse,
especially in a case when dealing with mouse over menus.
Dragging &
Dropping an Element:
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;
public class
testDragandDrop {
public static void main(String[] args) throws
InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://jqueryui.com/resources/demos/droppable/default.html");
WebElement draggable =
driver.findElement(By.xpath("//*[@id='draggable']"));
WebElement droppable = driver.findElement(By.xpath("//*[@id='droppable']"));
Actions action = new Actions(driver);
action.dragAndDrop(draggable,
droppable).perform();
}
}
Sliding an Element:
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;
public class
testSlider {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException
{
WebDriver driver = new FirefoxDriver();
driver.get("http://jqueryui.com/resources/demos/slider/default.html");
WebElement slider =
driver.findElement(By.xpath("//*[@id='slider']/a"));
Actions action = new Actions(driver);
Thread.sleep(3000);
action.dragAndDropBy(slider, 90,
0).perform();
}
}
Re-sizing an Element:
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;
public class
testResizable {
public static void main(String[] args) throws
InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://jqueryui.com/resources/demos/resizable/default.html");
WebElement resize =
driver.findElement(By.xpath("//*[@id='resizable']/div[3]"));
Actions action = new Actions(driver);
action.dragAndDropBy(resize, 400,
200).perform();
}
}
No comments:
Post a Comment