Drag and drop doesn't work with React JS web app

25 views
Skip to first unread message

Pradeep P

unread,
May 27, 2018, 9:14:56 AM5/27/18
to Selenium Users
Hi,

I'm automating a React JS app and it seems like drag and drop functionality is not working. I tried all different ways with dragAndDrop, Robot but still it doesn't work. Is there any defect here?

Actions action=new Actions(driver);
WebElement dragElement=driver.findElement(By.xpath(".//*[contains(text(),\"automation\")]/.."));
WebElement dropElement=driver.findElement(By.xpath("(.//div[@class=\"viewlet-title\"])[1]/.."));

// method 1
action.clickAndHold(dragElement).pause(2000).build().perform();
action.moveToElement(dropElement,10,10).pause(2000).build().perform();
action.release().pause(2000).build().perform();
Thread.sleep(2000);*/
//method 2
Robot robot = new Robot();
        robot.setAutoDelay(1000);
        int fromX=dragElement.getLocation().getX()+5;
        int fromY=dragElement.getLocation().getY()+5;
        int toX=dropElement.getLocation().getX()+5;
        int toY=dropElement.getLocation().getY()+5;
 
        robot.mouseMove(fromX, fromY);
        Thread.sleep(1000);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(1000);
        robot.mouseMove(toX, toY);
        Thread.sleep(1000);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        Thread.sleep(1000);*/
Reply all
Reply to author
Forward
0 new messages