如何在selenium中对这个可拖动列表进行排序

bf1o4zei  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(395)

实践环节https://demoqa.com/sortable
我用这个密码试过了

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();
}
u7up0aaq

u7up0aaq1#

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.

相关问题