拖放执行但未执行-WebDriver [英] Drag and drop gets executed but its not getting performed - webdriver

查看:57
本文介绍了拖放执行但未执行-WebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过这两个代码,但是它们没有被执行,有人可以告诉我为什么吗?

I have tried these two codes , it get executed but the action does not get performed ,Can any one tell me why?

//Type one approach
Actions action = new Actions(Browser.Driver);
IWebElement sourceElement = Browser.Driver.FindElement(By.XPath(Filexpath));
IWebElement targetElement = Browser.Driver.FindElement(By.XPath(NewXpath));

//Type two approach 
Actions Sourcebuilder = new Actions(Browser.Driver);
Actions SourceAction = Sourcebuilder.ClickAndHold(sourceElement);
Sourcebuilder.Build();
SourceAction.Perform();



/// move and drop
Actions builder = new Actions(Browser.Driver);
Actions action = builder.MoveToElement(targetElement);
builder.Release(targetElement);
builder.Build();
action.Perform();

预先感谢

推荐答案

尝试以下代码:

 Actions ac = new Actions(driver);
 ac.dragAndDrop(source element, target element);
 ac.build().perform();

它将在源元素的位置单击并按住,移至目标元素的位置,然后释放鼠标.

It will click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.

 Actions ac = new Actions(driver);
 ac.dragAndDropBy(source element, xOffset, yOffset);
 ac.build().perform();

它将单击并按住源元素的位置,移动给定的偏移量,然后释放鼠标.

It will click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.

    Actions ac = new Actions(driver);
    ac.clickAndHold(onElement);
    ac.moveToElement(toElement); or ac.moveToElement(toElement, xOffset, yOffset);
    ac.build().perform();

它将执行以上两个代码的操作.

It will do the action of the above two code.

我在Java上编写此代码.您可以转换为指定的语言.

I write this code on Java. You can convert in to your specified language.

引用自操作.

这篇关于拖放执行但未执行-WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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