using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Interactions;
namespace WebDriverActions
{
class WebDriverTest
{
static void Main()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("");
IWebElement source = driver.FindElement(By.CssSelector(""));
IWebElement target = driver.FindElement(By.CssSelector(""));
Actions action = new Actions(driver);
action.DragAndDrop(source, target).Perform();
}
}
}
The above will find an IWebElement
, source
, and drag it to, and drop it into the second IWebElement
, target
.
Drag and Drop using source and target webelement.
A convenience method that performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
/**
* Drag and Drop test using source and target webelement
*/
public class DragAndDropClass {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("");
WebElement source = driver.findElement(By.cssSelector(""));
WebElement target = driver.findElement(By.cssSelector(""));
Actions action = new Actions(driver);
action.build();
action.dragAndDrop(source, target).perform();
}
}
Drag an element and drop it at a given offset.
A convenience method that performs click-and-hold at the location of the source element, moves by a given offset (x and y, both integers), then releases the mouse.
WebElement source = driver.findElement(By.cssSelector(""));
Actions action = new Actions(driver);
action.build()
action.dragAndDropBy(source, x, y).perform(); // x and y are integers value