'How I can Sort this Draggable List in Selenium
Link for Practice https://demoqa.com/sortable
I tried with this code
Actions action=new Actions(driver);
List<WebElement> elements=driver.findElements(By.xpath("//*[@id=\"demo-tabpane-list\"]/div/div"));
for(int i=5;i>=0;i--) {
action.dragAndDrop(elements.get(0), elements.get(i)).build().perform();
}
Solution 1:[1]
List<WebElement> list = driver.findElements(By.xpath("//* [@id='demo-tabpane-list']/div/div"));
for(int i =1;i<list.size();i++) {
WebElement element = driver.findElement(By.xpath("//*[@id='demo-tabpane-list']/div/div["+ i +"]"));
WebElement destination6 = driver.findElement(By.xpath("//*[@id='demo-tabpane-list']/div/div[6]"));
WebElement destination5 = driver.findElement(By.xpath("//*[@id='demo-tabpane-list']/div/div[5]"));
WebElement destination4 = driver.findElement(By.xpath("//*[@id='demo-tabpane-list']/div/div[4]"));
WebElement destination3 = driver.findElement(By.xpath("//*[@id='demo-tabpane-list']/div/div[3]"));
WebElement destination2 = driver.findElement(By.xpath("//*[@id='demo-tabpane-list']/div/div[2]"));
WebElement destination1 = driver.findElement(By.xpath("//*[@id='demo-tabpane-list']/div/div[1]"));
Actions action = new Actions(driver);
if(element!=null) {
action.dragAndDrop(element, destination6).perform();
action.dragAndDrop(element, destination5).perform();
action.dragAndDrop(element, destination4).perform();
action.dragAndDrop(element, destination3).perform();
action.dragAndDrop(element, destination2).perform();
action.dragAndDrop(element, destination1).perform();
break;
}
}
Please enhance it as per your need.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |