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