Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag and drop function is not working in chromedriver using selenium webdriver and Node js for Test automation

Is there a way where I can make drag and drop to in selenium using Node.js? I am using the function shown below but it does not seem to work.

driver.actions().dragAndDrop(source,destination).perform())
like image 451
Faheem Avatar asked Aug 11 '17 07:08

Faheem


People also ask

How do you automate drag and drop functionality in selenium?

We can perform drag and drop action in Selenium with the help of Actions class. In order to perform the drag and drop movement we will use dragAndDrop (source, target) method. Finally use build(). perform() to execute all the steps.

How do you drag and drop elements from one frame to another?

switchTo(). frame(frameTwo); // move element to another frame WebElement elementTwo = driver. findElement(By. xpath("//body[@class='frameBody dropFrameBody']")); Actions actions2 = new Actions(driver); Actions action2 = actions2.

Can selenium move mouse?

A representation of any pointer device for interacting with a web page. There are only 3 actions that can be accomplished with a mouse: pressing down on a button, releasing a pressed button, and moving the mouse. Selenium provides convenience methods that combine these actions in the most common ways.


1 Answers

First of all, you forgot the build() method.
Second of all, inspect the html code and find if your drag&drop is into Iframe tag.
If it is, then you need to switch to that Iframe.

So:

driver.switchTo().frame(driver.findElement(By.xpath("PutYourXpathIframe")));  

Actions a = new Actions(driver);
WebElement source = driver.findElement(By.id("PutYourSourceId"));
WebElement target = driver.findElement(By.id("PutyourTargerId"));
a.dragAndDrop(source,target).build().perform();

In the end you may want to switch back to default content:

driver.switchTo().defaultContent();
like image 86
BOB Avatar answered Sep 20 '22 23:09

BOB