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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM