单击并拖动Selenium(chrome webdriver)不会拖动,但会按住 [英] Click and Drag Selenium (chrome webdriver) is not dragging, but will click and hold

查看:580
本文介绍了单击并拖动Selenium(chrome webdriver)不会拖动,但会按住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图将一个可以单击的列表元素自动化,然后将其拖动到ol元素的不同部分,然后保存。但是测试将尽一切努力去保持元素。它不会按偏移量移动,也不会移动到目标元素。

So I am trying to automated a list element that can be clicked, and dragged to different portions of the ol elements, and then saved. But the test will oly go as far as to hold the element. it will not move by offset, and it will not move to the target element.

Chrome webdriver,Java / Selenium

Chrome webdriver, Java/Selenium

public void clickAndDragListElement() {
    Actions hold = new Actions(driver);
    hold.clickAndHold(targetHoldElement)
        .moveToElement(targetDestinationElement)
        .release(targetHoldElement)
        .build()
        .perform();
}

(WebElement在元素外部定义)

(WebElements are defined outside the element)

推荐答案

new Actions(driver)
                .moveToElement(source)
                .pause(Duration.ofSeconds(1))
                .clickAndHold(source)
                .pause(Duration.ofSeconds(1))
                .moveByOffset(1, 0)
                .moveToElement(destination)
                .moveByOffset(1, 0)
                .pause(Duration.ofSeconds(1))
                .release().perform();

这篇关于单击并拖动Selenium(chrome webdriver)不会拖动,但会按住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆