WebDriver driver = new ChromeDriver(); //Launch the chrome browser
driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement from = driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement to = driver.findElement(By.xpath("//*[@id='mydropzone']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(from, to).perform();
答案 0 :(得分:0)
我将其放在Junit测试中。对我来说很好。
但是我注意到您没有将属性设置为使用本地chromedriver。
您下载了chromedriver吗?
private WebDriver driver;
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver",
//"C:/path/to/your/chromedriver.exe"
"/path/to/your/chromedriver"); // Might be this.
driver= new ChromeDriver();
}
@After
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void testDragNDrop() {
driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement from = driver.findElement(By.xpath("//*[@id=\"todrag\"]/span[2]"));
WebElement to = driver.findElement(By.xpath("//*[@id='mydropzone']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(from, to).perform();
}