Drag and Drop not working in selenium code

后端 未结 4 1056
半阙折子戏
半阙折子戏 2021-01-29 13:56

Drag and Drop is not working in my selenium code below, can anyone help me?

package selenium;

import java.util.concurrent.TimeUnit;

import org.apache.log4j.Bas         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-29 14:46

    Your drag and drop element present under iFrame tag. So first you need to switch into frame and then perform drag and drop.

    Use below code :

    System.setProperty("webdriver.chrome.driver","D:/Application/chromedriver.exe");
    driver = new ChromeDriver();        
    driver.manage().window().maximize();
    driver.get("http://jqueryui.com/droppable/");               
    driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
    driver.switchTo().frame(0); // either use index or frame element
    WebElement  from= driver.findElement(By.id("draggable"));
    WebElement  to=driver.findElement(By.id("droppable"));
    new Actions(driver).dragAndDrop(from, to).build().perform();
    

    Please note : if element id is there then please use id selector instead of xpath

提交回复
热议问题