The code below is used for testing drag and drop functionality using WebDriver. The trouble which I am facing with the code is that it is unable to detect the XPath.
public class draganddrop
{
public static void main(String[] args) throws InterruptedException
{
// opening site for practicing user interaction by mouse using webdriver and action class
WebDriver driver = new ChromeDriver();
String URL = "http://www.dhtmlx.com/docs/products/dhtmlxTree/index.shtml";
driver.get(URL);
// It is always advisable to Maximize the window before performing DragNDrop action
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
WebElement From = driver.findElement(By.xpath(".//*[@id='treebox1']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"));
WebElement To = driver.findElement(By.xpath(".//*[@id='treebox2']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(From).moveToElement(To).release(To).build();
dragAndDrop.perform();
Thread.sleep(2000);
}
}
The error message
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='treebox1']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"}