拖放在C#中不起作用(Selenium Web Driver)

时间:2016-04-07 13:49:15

标签: c# selenium-webdriver

是否有一些简单的拖放功能的工作代码?

  1. 选择图片
  2. 拖放到文件夹
  3. 释放鼠标。
  4. 我在这里尝试了所有可能的代码示例,但在Visual Studio(C#)中都不起作用。

    WebElement firstdoc = driver.FindElement(By.XPath("//*@id='body']/section/div/div[5]/ul/li[1]")); 
    IWebElement Fundingfolder = driver.FindElement(By.XPath("//*[@id='body']/section/div/div[3]/div[1]/div[1]/di‌​v[1]/div[1]")); 
    IWebElement secdoc = driver.FindElement(By.XPath("//*[@id='body']/section/div/div[5]/ul/li[1]/div[1]"‌​)); 
    IWebElement Incomefolder = driver.FindElement(By.XPath("//*[@id='body']/section/div/div[3]/div[1]/div[1]/di‌​v[2]/div[1]"));
    
    
    Actions Builder = new Actions(driver); 
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); 
    Builder.MoveToElement(firstdoc); 
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20)); 
    Builder.ClickAndHold(firstdoc); 
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20)); 
    Builder.DragAndDrop(firstdoc, Fundingfolder); 
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20)); 
    Builder.Release(Fundingfolder).Perform(); 
    driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
    

1 个答案:

答案 0 :(得分:0)

IWebElement drag = driver.FindElement(By.Id(id));

IWebElement drop = driver.FindElement(By.XPath(xPath));

(new Actions(driver)).ClickAndHold(drag).MoveToElement(drop).DragAndDrop(drag, drop).Perform();