Why drag and drop is not working in Selenium Webdriver?

后端 未结 12 1663
借酒劲吻你
借酒劲吻你 2021-01-11 11:45

I am trying to drag an element into another element using Selenium WebDriver but it\'s not working. I tried all the solutions which I can find on internet but none of the so

12条回答
  •  时光说笑
    2021-01-11 11:55

    I've tried a bunch of workarounds, this one seems to work for me using macOS and chromedriver

    public void dragAndDrop(WebElement source, WebElement target) throws AWTException {
        new Actions(driver).dragAndDrop(source, target).release().build().perform();
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_ESCAPE);
        robot.keyRelease(KeyEvent.VK_ESCAPE);
    }
    

提交回复
热议问题