我无法使用动作类进行拖放。在动作类中有很多解决方案。在webdriver中还有其他任何解决方案

时间:2016-07-06 13:02:13

标签: selenium selenium-webdriver

请帮助解决其他动作类..我必须拖放元素;来自元素;到元素'在java中

1 个答案:

答案 0 :(得分:0)

我建议您使用'Robot'进行拖放操作。这很直截了当。我如何使用它的一个例子可能对你有用......

// Location of your first element
Point coordinates1 = driver.findElement(By.xpath("your element xpath")).getLocation();

// Location of your second Element
Point coordinates2 = driver.findElement(By.xpath("your element xpath")).getLocation();

    Robot robot = new Robot();
    robot.setAutoDelay(2000);
    robot.setAutoWaitForIdle(true);

    // go to the location of the first element
    robot.mouseMove(coordinates1.getX(), coordinates1.getY());

    robot.delay(500);

    // Press the mouse on the first location
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);

    robot.delay(500);

    // Move the mouse to the second location
    robot.mouseMove(coordinates2.getX(), coordinates2.getY());

    // Release the mouse on the second location
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK)