无法执行拖动和放大使用Actions删除

时间:2016-08-09 06:47:36

标签: java selenium

package Chrome_Packg;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class testFirefox_DragDrop {

    public static void main(String[] args) throws InterruptedException {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://jqueryui.com/droppable/");

        WebElement drag=driver.findElement(By.xpath("/html/body/div[1]"));//drag element
        WebElement drop=driver.findElement(By.xpath("/html/body/div[2]"));//drop element

        Actions action=new Actions(driver);
        Thread.sleep(3000);
        action.dragAndDrop(drag, drop).perform();


    }

}

执行代码后,使用Run as java application,在输出中我什么都没得到。

1 个答案:

答案 0 :(得分:0)

以下是您尝试使用的同一网站的代码段,您也可以在此处找到示例selenium Drag and Drop example

driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.navigate().to("http://jqueryui.com/droppable/");
    //Wait for the frame to be available and switch to it
    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".demo-frame")));
    WebElement Sourcelocator = driver.findElement(By.cssSelector(".ui-draggable"));
    WebElement Destinationlocator = driver.findElement(By.cssSelector(".ui-droppable"));
    dragAndDrop(Sourcelocator,Destinationlocator);
    String actualText=driver.findElement(By.cssSelector("#droppable>p")).getText();
    Assert.assertEquals(actualText, "Dropped!");