selenium(八)---java+selenium实现拖拽

  • 鼠标拖动API
    Actions action = new Actions(webdriver);

  • source-要拖动的元素A,target-拖动元素A到达的目标元素
    action.dragAndDrop(source, target);
    source-要拖动的元素A,拖动元素移动多少,标准以元素A左上角为准,拖动元素相对元素A移到右边的时候x为正值,左边是负值,拖动元素相对元素A移到上边的时候y为负值,下边是正值。(左负右正,上负下正)
    action.dragAndDropBy(source, xOffset, yOffset);

  • 举例:
    //找到我们所要拖动的元素A
    WebElement A = driver.findElement(By.xpath(“XXXX”));
    Actions action = new Actions(driver);
    //鼠标拖动A向左移动530,之后释放鼠标
    action.dragAndDropBy(A, -530, 0).perform();
    // 鼠标拖动A向上移动100,向右移动570之后释放鼠标
    action.dragAndDropBy(A, 570, -100).perform();


文章参考:http://www.mamicode.com/info-detail-2955806.html

猜你喜欢

转载自blog.csdn.net/qq_36800800/article/details/114087719
今日推荐