【问题标题】:Not able to perform drag & drop using Actions无法使用操作执行拖放
【发布时间】:2016-08-09 06:47:35
【问题描述】:
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 应用程序,在输出中我什么也没得到。

【问题讨论】:

标签: java selenium


【解决方案1】:

这是您正在尝试的同一网站的代码 sn-p,您也可以在此处找到示例 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!");

【讨论】:

    猜你喜欢
    • 2016-05-25
    • 1970-01-01
    • 2020-07-27
    • 2018-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 2021-10-02
    相关资源
    最近更新 更多