java - 如何在 react-dnd-treeview 库上使用 Selenium 测试拖放

标签 java selenium selenium-webdriver drag-and-drop

我正在尝试在 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/

相关文章:

java - 使用命令行在Windows中压缩文件夹

java - 异常堆栈上的 Mule JUnit 测试

java - 如何使用Selenium java在浏览器中的两个窗口之间切换

python - Selenium 遍历下拉选择中的选项

Selenium Webdriver等待来自另一个元素的元素

java - Miglayout 按钮溢出约束

按 ReceivedDate 搜索 JavaMail,不能精确到秒?

selenium - 在 Jenkins 上运行 Dockerized Selenium Grid

c# - Browsermob 代理 - HAR 文件不如手动 HAR 完整?

selenium - 如何查找包含特定子元素的元素?