Perform different actions in once, like: drag-and-drop, sliding, selecting multiple items.
In below example, we are performing drag And Drop of web-element
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://jqueryui.com/draggable/#sthash.4eGmtpmo.dpuf");
driver.manage().timeouts().pageLoadTimeout(18,
TimeUnit.SECONDS);
driver.switchTo().frame(driver.findElement(By.className("demo-frame")));
WebElement element =(new WebDriverWait(driver, 50)) .until(ExpectedConditions.presenceOfElementLocated((By.id("draggable"))));
Actions action = new Actions(driver);
action.dragAndDropBy(element, 120,
150).build().perform();
Further details:-
public class Action {
private static WebDriver driver;
@Test
public void droppable() {
driver.get("http://jqueryui.com/demos/droppable/");
WebElement draggable = driver.findElement(By.id("draggable"));
WebElement droppable = driver.findElement(By.id("droppable"));
new Actions(driver).dragAndDrop(draggable, droppable).build().perform();
}
@Test
public void selectMultiple() throws InterruptedException {
driver.get("http://jqueryui.com/demos/selectable/");
List<WebElement> listItems = driver.findElements(By
.cssSelector("ol#selectable *"));
Actions builder = new Actions(driver);
builder.clickAndHold(listItems.get(1)).clickAndHold(listItems.get(2))
.click();
Action selectMultiple = builder.build();
selectMultiple.perform();
}
@Test
public void sliding() {
driver.get("http://jqueryui.com/demos/slider/");
WebElement draggable = driver.findElement(By
.className("ui-slider-handle"));
new Actions(driver).dragAndDropBy(draggable, 120, 0).build().perform();
}
}
private static WebDriver driver;
@Test
public void droppable() {
driver.get("http://jqueryui.com/demos/droppable/");
WebElement draggable = driver.findElement(By.id("draggable"));
WebElement droppable = driver.findElement(By.id("droppable"));
new Actions(driver).dragAndDrop(draggable, droppable).build().perform();
}
@Test
public void selectMultiple() throws InterruptedException {
driver.get("http://jqueryui.com/demos/selectable/");
List<WebElement> listItems = driver.findElements(By
.cssSelector("ol#selectable *"));
Actions builder = new Actions(driver);
builder.clickAndHold(listItems.get(1)).clickAndHold(listItems.get(2))
.click();
Action selectMultiple = builder.build();
selectMultiple.perform();
}
@Test
public void sliding() {
driver.get("http://jqueryui.com/demos/slider/");
WebElement draggable = driver.findElement(By
.className("ui-slider-handle"));
new Actions(driver).dragAndDropBy(draggable, 120, 0).build().perform();
}
}
Donate:
Please
Donate the some money (anything do you want) for my
blog
if you beneficial for this, I will provide more real example for the
latest
technique for whom who wants to make a carrier in IT field or solved
some
problem, My Name is – RITESH KUMAR SINGH A/C number- 913010044116345 AXIS
Bank
LTD :- Vaishali NCR, India-001
No comments:
Post a Comment