这不起作用(例如:https://www.w3schools.com/html/html5_draganddrop.asp)
var item = WebDriver.FindElement(By.XPath(@"//img[@src='img_w3slogo.gif']"), 30);
var container = WebDriver.FindElement(By.XPath(@"//div[@id='div2']"), 30);
var actions = new OpenQA.Selenium.Interactions.Actions(this.WebDriver);
actions.DragAndDrop(item, container).Build().Perform();
System.Threading.Thread.Sleep(3000);
如果有帮助的话......
If it helps....
public static void DragAndDrop(IWebElement element1, IWebElement element2)
{
WaitForElementEnabled(element1);
WaitForElementEnabled(element2);
var builder = new Actions(_webDriver);
var dragAndDrop = builder.ClickAndHold(element1).MoveToElement(element2).Release(element2).Build();
dragAndDrop.Perform();
}
public static void WaitForElementEnabled(IWebElement element)
{
try { _wait.Until(webDriver => element.Enabled); }
catch (StaleElementReferenceException) { if (!WaitForNotFoundElement_Enabled(element)) { LogFunctions.WriteError("Enabled - Stale Element Exception"); TakeScreenshot("elementNotFound"); throw; } }
}
这篇关于为什么这个 Selenium 的拖放 C# 代码在 Chrome 上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!