Selenium RC DragAndDrop

来源:互联网 发布:mac os 无法更新 编辑:程序博客网 时间:2024/06/01 21:32
(1) dragAndDrop - Locates the target element and drags the element by x pixels horizontally and y pixels vertically.

In the IDE this should look like;

Command - dragAndDrop
Target - [ locator of the target element ]
Value - [ (x-pixels),(y-pixels) ]

    - where x-pixels/y-pixels can be negative (left/up respectively) or positive (right/down respectively)

[csharp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1.          string dragLocator = @"//a[@id=abc]";  
  2.          string dropLocator = @"//td[text()='drop to here']";  
  3.   
  4. decimal dropX = selenium.GetElementPositionLeft(dropLocator);  
  5. decimal dropY = selenium.GetElementPositionTop(dropLocator);  
  6. decimal endX = selenium.GetElementWidth(dropLocator);  
  7. decimal endY = selenium.GetElementHeight(dropLocator);  
  8. endX = Math.Round(dropX + (endX / 2));  
  9. endY = Math.Round(dropY + (endY / 2));  
  10. String movementsString = "" + endX + "," + endY;  
  11.   
  12. selenium.DragAndDrop(dragLocator, movementsString);  

(2) dragAndDropToObject - Locates the target element and drags the element to the centre pixel location of the destination element

In the IDE this should look like;
Command - dragAndDropToObject Target - [ locator of the target element ] Value - [ locator of the destination element you want to drop it on top of ]
[csharp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. string dragLocator = @"//a[@id=abc]";  
  2. string dropLocator = @"//td[text()='drop to here']";  
  3.   
  4. Selenium.DragAndDropToObject(dragLocator, dropLocator);  

(3) Use MouseDownAt, MouseMoveAt, MouseUpAt to resolve drag and drop.

[csharp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. string dragLocator = @"//a[@id=abc]";  
  2. string dropLocator = @"//td[text()='drop to here']";  
  3.   
  4.   
  5.     selenium.MouseMove(dragLocator);  
  6.     Thread.Sleep(3000);  
  7.     selenium.MouseDownAt(dragLocator, "0,0");  
  8.     Thread.Sleep(3000);  
  9.     selenium.MouseMoveAt(dropLocator, "0,0");  
  10.     Thread.Sleep(3000);  
  11.     selenium.MouseUpAt(dropLocator, "0,0");  
  12.     Thread.Sleep(3000);   


0 0
原创粉丝点击