qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

Selenium—实现网页元素拖拽

Drag and Drop, 使用鼠标实现元素拖拽的操作貌似很复杂, 在Selenium中, 借助OpenQA.Selenium.Interactions.Actions类库中提供的方法, 实现起来还是比较简单的。道理如下:
  1. 找到要拖拽的页面元素-源(source)。
  2. 找到要释放的页面元素-目标(target), 页面显示的这个元素可能是个坑, 但是在页面代码中他就是一个元素。
  3. 借助(new Actions(IWebDriver)).DragAnddrop( source, target).Perform(), 完成元素拖放操作。
  示例代码:
// drag and drop
using OpenQA.Selenium.Interactions;
SIE.InternetExplorerDriver driver = new SIE.InternetExplorerDriver();
if (source != null && target != null)
{
// drag and drop
new Actions(driver).DragAndDrop(source, target).Perform();
}

posted on 2014-08-27 10:29 顺其自然EVO 阅读(340) 评论(0)  编辑  收藏 所属分类: 测试学习专栏


只有注册用户登录后才能发表评论。


网站导航:
 
<2014年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜