Selenium Web драйвер не выполняет перетаскивание
Веб-драйвер Selenium не выполняет перетаскивание, поэтому утверждение каждый раз терпит неудачу, так как после удаления перетаскиваемого элемента в выпадающем списке нет текста. Я добавил скриншот для перетаскиваемых элементов, дропзоны и выпадающего списка, может кто-нибудь посоветовать мне, как решить проблему?
// Ниже приведены два метода dragAnItem() и dropItem () в классе;
public class DragAndDrop {
WebDriver driver;
public DragAndDrop(WebDriver driver){
this.driver = driver;
}
public void dragAnItem(){
//Element on which need to drag.
WebElement source = driver.findElement(By.xpath("//div[@id='todrag']/span"));
//Element on which need to drop.
WebElement target =driver.findElement(By.id("mydropzone"));
try {
Thread.sleep(5000);
//Using Actions class for drag and drop.
Actions act = new Actions(driver);
//Using Action for Dragged and dropped.
Action dragAndDrop = act.clickAndHold(source)
.moveToElement(target)
.release(target)
.build();
dragAndDrop.perform();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String droppedItem(){
return driver.findElement(By.id("droppedlist")).getText();
//return driver.findElement(By.xpath("//div[@id='droppedlist']")).getText();
}
}
// DragAndDropTest, как показано ниже;
public class DragAndDropTest {
@Test
public void dragAndDropTest(){
System.setProperty("webdriver.chrome.driver", "C:\\Project\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
DragAndDrop dragandDrop = new DragAndDrop(driver);
dragandDrop.dragAnItem();
String droppedText = dragandDrop.droppedItem();
System.out.println("AfterDrop:" + droppedText);
Assert.assertTrue(droppedText.equals("Draggable 1"));
driver.close();
driver.quit();
}
}