2016-08-09 10 views
0
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(); 


    } 

} 

Nach der Ausführung des Codes, mit Run as Java-Anwendung, in der Ausgabe bekomme ich nichts. HierDrag & Drop nicht möglich mit Aktionen

Antwort

0

ist der Code-Snippet für die gleiche Website, die Sie versuchen, auf und Sie können auch das Beispiel finden hier 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!");