我正在尝试在 React 应用程序上测试简单的拖放行为。
我正在使用 react-dnd-treeview图书馆和their example website测试我的测试用例。
当我在调试中运行测试时,我没有收到任何错误并且 Selenium 能够获得正确的元素,但是什么也没有发生,我无法创建或可视化任何类型的操作,即使在尝试之后也是如此这么多不同的答案in this similar question , 但徒劳无功。
这是我正在使用的代码:
package tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import java.io.File;
public class DAndDJava {
public static void main(String[] args) {
File file = new File("C:/misc/chromedriver.exe");
System.setProperty("webdriver.chrome.driver" , file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://teleport.github.io/react-dnd-treeview/example/dist/index.html");
WebElement dragPoint = driver.findElement(By.xpath ("//*[@id=\"root\"]/div/div/div[3]/div[2]/div[2]/div/div/div[3]/div[2]/div/div[1]/div[3]/div[1]/div"));
WebElement dropPoint = driver.findElement(By.xpath ("//*[@id=\"root\"]/div/div/div[3]/div[2]/div[2]/div/div/div[3]/div[2]/div/div[1]/div[3]/div[1]"));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(dragPoint)
.moveToElement(dropPoint)
.release(dropPoint)
.build();
dragAndDrop.perform();
driver.quit();
}
}
最佳答案
你能试试下面的代码吗:
Action dragAndDrop = builder.clickAndHold(dragPoint)
.moveToElement(dropPoint)
.moveByOffset(0,10)
.release()
.build()
.perform() ;
关于java - 如何在 react-dnd-treeview 库上使用 Selenium 测试拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50295160/