selenium + java jquery元素——将元素拖动到指定处

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 ();


    }
}

运行之前:

selenium + java jquery元素——将元素拖动到指定处_第1张图片

运行之后:

selenium + java jquery元素——将元素拖动到指定处_第2张图片

你可能感兴趣的:(基础篇,持续更新,..,selenium,java,元素拖拽,自动化)