selenium拖动元素java,单击并拖动Selenium(chrome webdriver)不会拖动,但会按住

本文探讨了在使用Selenium与Java进行Web自动化测试时遇到的一个问题:无法正确执行列表元素的拖放操作。通过分析,发现测试代码只能持有所点击的元素,但无法将其移动到目标位置。为了解决这个问题,提出了一个新的解决方案,该方案详细描述了如何通过调整动作序列,包括暂停、点击、按住、移动元素和释放,来成功地执行拖放操作。
摘要由CSDN通过智能技术生成

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

public void clickAndDragListElement() {

Actions hold = new Actions(driver);

hold.clickAndHold(targetHoldElement)

.moveToElement(targetDestinationElement)

.release(targetHoldElement)

.build()

.perform();

}

(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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值