无法使用Java在Selenium Web-Driver中执行拖放操作

时间:2014-12-09 12:27:58

标签: java selenium selenium-webdriver drag-and-drop

以下是代码。拖放不起作用。请告诉我代码中的错误。

WebDriver driver = new FirefoxDriver();
    String URL ="http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_draganddrop";
    driver.get(URL);
    driver.manage().window().maximize();
    WebDriverWait  frame_Test = new WebDriverWait(driver, 10);
    frame_Test.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("iframeResult")));
    WebElement From = driver.findElement(By.xpath("//img[@id='drag1']"));
    WebElement To =driver.findElement(By.xpath("//div[@id='div1']"));
    Actions builder = new Actions(driver);
    builder.clickAndHold(From).moveToElement(To).release(From).build( ).perform();

1 个答案:

答案 0 :(得分:0)

你得到的是什么错误?你在下面试过吗?

WebElement element = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));    
(new Actions(driver)).dragAndDrop(element, target).perform();