public class Actionss {
public static void main (String[] args) throws InterruptedException {
//驱动配置
System.setProperty("webdriver.chrome.driver","D:\\driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver ();
driver.manage ().window ().maximize ();
driver.get("http://jqueryui.com/resources/demos/droppable/default.html");
Thread.sleep ( 2000 );
//定位元素
WebElement move = driver.findElement ( By.id ("draggable") );
WebElement ele = driver.findElement ( By.id ( "droppable" ) );
//将定位元素拖动到指定处
Actions action =new Actions ( driver );
action.dragAndDrop ( move,ele ).build ().perform ();
assert (driver.findElement ( By.xpath ( "//*[@id='droppable']/p[text()='Dropped!']") ).isDisplayed ()==true);
Thread.sleep ( 2000 );
driver.quit ();
}
}
运行之前:
运行之后: