Module 16 - Drag and Drop functionality | Selenium Forum
M
Posted on 05/06/2016
Hi,
I am using the same code which is show in the video but during run the script eclipse show "No Such Element Exception" even the firepath is show the xpath of the dragger item.


Code :-

import java.util.concurrent.TimeUnit;

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.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;

public class Dragging {

public static void main(String[] args) throws InterruptedException {

FirefoxProfile profile = new FirefoxProfile(); /*NOTE :- Firefor profile is used when native events are not
Working like when move to mouse over a menu, sub menu not display
for that we use setEnableNativeEvents(true)*/

profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
//WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://jqueryui.com/draggable/");
WebElement drag = driver.findElement(By.xpath("//div[@id='draggable']")); =====>>> Not able to find that element
Thread.sleep(2000L);
Actions act = new Actions(driver);
act.dragAndDropBy(drag, 50, 50).build().perform();
}

}

M
Replied on 05/06/2016

Use frames


M
Replied on 05/06/2016

package module15;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

//http://code.google.com/p/selenium/wiki/AdvancedUserInteractions#Native_events_versus_synthetic_events
public class Dragging {

/**
* @param args
*/
public static void main(String[] args) {
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);


driver.get("http://jqueryui.com/draggable/");
// use below line your problem will be solved
driver.switchTo().frame(0);

WebElement obj = driver.findElement(By.xpath("//div[@id='draggable']"));

Actions act = new Actions(driver);
act.dragAndDropBy(obj, 50, 50).build().perform();
//act.clickAndHold(obj).dragAndDropBy(obj, 200, 200).build().perform();
driver.switchTo().defaultContent();


}

}


M
Replied on 05/06/2016

Yes.
Thanks its working.. My Mistake i should investigate it.