我正在尝试在AngularJS演示站点上拖放元素,但我无法实现结果。
对于我的练习,我正在使用https://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/nested,而我正试图拖延将'第7项(从dropzone B)'放到'第3项(在容器1中)'。
我使用.getText()
方法确保我的xpath
指向正确的元素。但它仍然无法正常工作。以下是我的代码:
public void SetUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "F:\\Drivers\\chromedriver.exe");
d = new ChromeDriver();
d.manage().window().maximize();
d.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
d.get("https://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/nested");
Thread.sleep(2000);
((JavascriptExecutor)d).executeScript("scroll(4,400)");
WebElement src = d.findElement(By.xpath("html/body/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/div/div/ul/li[1]/div"));
System.out.println("The src element is:" +src.getText());
WebElement destn = d.findElement(By.xpath("html/body/div[2]/div[2]/div[2]/div[1]/div[1]/div[1]/div/div/ul/li[1]/div/div[2]/ul/li/div"));
System.out.println("The src element is:" +destn.getText());
org.openqa.selenium.Point pt1 = src.getLocation();
org.openqa.selenium.Point pt2 = destn.getLocation();
int xCord1 = pt1.getX();
int yCord1 = pt1.getY();
int xCord2 = pt2.getX();
int yCord2 = pt2.getY();
System.out.println("The X & Y cordinate of the src is:" +xCord1+ " & " +yCord1);
System.out.println("The X & Y cordinate of the destn is:" +xCord2+ " & " +yCord2);
Actions ac = new Actions(d);
Action dragAndDrop = ac.clickAndHold(src).moveToElement(destn, 334, 661).release(destn).build();
dragAndDrop.perform();
}