Drag and drop not working using Actions when draggable=true using Selenium and C#(使用 Selenium 和 C# 在 draggable=true 时拖放不工作)
问题描述
元素被正确识别,我可以看到鼠标在这两个元素之间移动,但没有发生拖放.单击并按住时,UI 未显示任何突出显示.也没有错误.
Elements are identified correctly and i can see mouse moving between this two elements but drag and drop not happening. Ui not displayed any highlights when click and hold. No errors also.
我尝试了在不同讨论中提出的不同解决方案,但它们都不适合我
I have tried different solutions suggested on different discussions none of them working for me
我的代码
_actions = new Actions(Driver.WebDriver);
var dragAndDrop = _actions.ClickAndHold(parentRow)
.MoveToElement(childRow )
.Release(target)
.Build();
dragAndDrop.Perform();
Driver.Wait();
这就是我识别元素的方式
This is how i am identifying elements
var childList =Driver.WebDriver.FindElements(By.ClassName("itl-treeNode-title"));
var parentRow = childList.FirstOrDefault(x => x.Text.Equals(parentSrc)).FindElement(By.XPath("following-sibling::*[1]"));
var childRow = childList.FirstOrDefault(x => x.Text.Equals(childSrc)).FindElement(By.XPath("following-sibling::*[1]"));
相同的代码可以在我们应用程序的另一个用户界面上运行.
Same code works on another ui on our application.
我现在已经像下面这样更改了我的代码,现在我得到了陈旧的元素异常——因为我需要动态识别这个元素,所以我不能使用这里提到的 POM 解决方案 https://www.softwaretestingmaterial.com/stale-element-reference-exception-selenium-webdriver/#How-To-Overcome-Stale-Element-Reference-Exception-in-Selenium
I have now changed my code like below and now i am getting stale element exception- Since i need to identify this element dynamically i can not use the POM solution mentioned here https://www.softwaretestingmaterial.com/stale-element-reference-exception-selenium-webdriver/#How-To-Overcome-Stale-Element-Reference-Exception-in-Selenium
var childList = Driver.WebDriver.FindElements(By.ClassName("itl-treeNode-title"));
var parent = childList.FirstOrDefault(x => x.Text.Equals(parentSrc)).FindElement(By.XPath("parent::*"));
var parentRow = parent.FindElement(By.ClassName("itl-treenode-content-cover"));
var child = childList.FirstOrDefault(x => x.Text.Equals(childSrc)).FindElement(By.XPath("parent::*"));
var childRow = child.FindElement(By.ClassName("itl-treenode-content-cover"));
childRow.Click();
//try
//{
// (new Actions(Driver.WebDriver)).DragAndDrop(childRow, parent).Perform();
/
本文标题为:使用 Selenium 和 C# 在 draggable=true 时拖放不工作


- 使用 rss + c# 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01