当有多个元素时,如何在selenium中拖放


以下代码不起作用。reportDataFields显示一个项目列表(用于ex abc、abd、abe),我想选择abc并将其放入目标。它也不会显示任何错误消息。

Actions action = new Actions(driver);
List<WebElement> reportFields = driver.findElements(By.className("reportDataFields"));
WebElement target = driver.findElement(By.id("rptDataSections"));

for (int i = 0; i < reportFields.size(); i++) {

    if (reportFields.get(i).getText().equals(Section)) {
        action.dragAndDrop(reportFields.get(i), target).release().build().perform();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}

转载请注明出处:http://www.yinxuebaozhuang.com/article/20230526/1852834.html