Why this Selenium's drag and drop C# code is not working on Chrome?

前端 未结 2 865
情歌与酒
情歌与酒 2021-01-25 22:05

This doesn\'t work (e.g.: https://www.w3schools.com/html/html5_draganddrop.asp)

var item = WebDriver.FindElement(By.XPath(@\"//img[@src=\'img_w3slogo.gif\']\"),          


        
2条回答
  •  广开言路
    2021-01-25 23:07

    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; } }
         }
    

提交回复
热议问题