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


    }
}

运行之前:

运行之后:

猜你喜欢

转载自blog.csdn.net/qq_36969649/article/details/84137456