首页 > Web开发 > 详细

Selenium - 实现网页元素拖拽

时间:2014-08-22 19:22:39      阅读:382      评论:0      收藏:0      [点我收藏+]

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

 

Selenium - 实现网页元素拖拽

原文:http://www.cnblogs.com/qixue/p/3929942.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!