Selenium Webdriver(C#):拖放已执行但没有任何反应

时间:2014-01-03 23:06:56

标签: selenium

我无法使用之前给出的示例代码将W3Schools图像拖放到矩形中。我尝试过Firefox,Chrome和IE网络驱动程序,一切都没有发生。

Firefox版本26.0

Chrome版本:31.0.1650.63 m

Internet Explorer版本:11

     FirefoxDriver browser = new FirefoxDriver(); //Open up a Firefox browser

     browser.Url = "http://www.w3schools.com/html/html5_draganddrop.asp";
     System.Threading.Thread.Sleep(5000); // Wait so I can see what's happening
     IWebElement imageToDragAndDrop = browser.FindElementById("drag1");
     IWebElement boxToDragImageInto = browser.FindElementById("div2");

     Actions actions = new Actions(browser);

     // Attempt 1: Calling the DragAndDrop method did not work
     // actions.DragAndDrop(imageToDragAndDrop, boxToDragImageInto).Build().Perform(); 

     // Attempt 2: Calling the DragAndDrop method again but with the method calls on separate lines
     //actions.DragAndDrop(imageToDragAndDrop, boxToDragImageInto);
     //actions.Build();
     //actions.Perform();

     // Attempt 3: Calling the ClickAndHold, MoveToElement, Release methods did not work either
     actions.ClickAndHold(imageToDragAndDrop);
     actions.MoveToElement(boxToDragImageInto);
     actions.Release(imageToDragAndDrop);
     actions.Build();
     actions.Perform();

1 个答案:

答案 0 :(得分:0)

HTML5拖放是Selenium的一个已知问题;

https://code.google.com/p/selenium/issues/detail?id=6315&thanks=6315&ts=1380031813

尝试直接使用javascript,如此处所述;

HTML5 Drag and Drop using Selenium Webdriver for Ruby