【问题标题】:Drag & Drop using Selenium with Java for automation testing使用 Selenium 和 Java 进行拖放以进行自动化测试
【发布时间】:2017-10-12 11:08:55
【问题描述】:

我正在使用 Selenium 工具进行自动化项目工作。我正在尝试在 Web 应用程序中实现拖放概念,很难将对象拖放到目标(放置位置)。以下代码用于实现此目的:

Actions action = new Actions(driver);
Actions actions = new Actions(driver);
WebElement Destination = driver.findElement(By.xpath("html/body/div[1]/div/div/div[4]/div/div/ul"));
action.moveToElement(element);
action.build().perform();
action.clickAndHold(element).moveToElement(Destination).release(Destination).build();
actions.perform();

我不应该使用“移动偏移”选项。

您能帮我解决这个问题(或)有什么建议吗?

【问题讨论】:

    标签: javascript java selenium


    【解决方案1】:

    来自文档drag-and-drop

    你可以这样做:

    Actions actions = new Actions(driver);
    WebElement element = driver.findElement(By.name("source")); //source
    WebElement Destination = driver.findElement(By.xpath("html/body/div[1]/div/div/div[4]/div/div/ul")); //target
    actions.dragAndDrop(element, Destination).perform();
    

    您的代码中的“元素”是什么?我可以想象是“源”元素。

    【讨论】:

    • 是的,“元素”是我代码中的源元素。问题是当我开始拖动时,源“元素”会动态变化。请您给出如何找到动态网页元素的解决方案。
    • 你能编辑你的问题,插入一些关于你的 html 的信息吗?
    猜你喜欢
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多