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())
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.
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.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With