Unable to scroll or drag and drop using Actions Class | Selenium Forum
M
Posted on 05/04/2016
Hello Ashish,

Yesterday I tried running Drag and Drop and Scrollable programs from your source code and they are failing.Its saying

[b:2l543hdj]org.openqa.selenium.NoSuchElementException[/b:2l543hdj] . I remember you taking examples of Java Script Executor as other option.Currently the source code does not have any example of Java Script Executor.Could you please send me few programs which you had used for demo purpose during lectures.

Below is the program given by you: ( I am using the http://jqueryui.com/slider/ site.Unable to locate the slider element)

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
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;

import com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration;


public class Slider {

/**
* @param args
*/
public static void main(String[] args) {
//FirefoxProfile profile = new FirefoxProfile();
//profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://jqueryui.com/demos/slider/");

WebElement scroll = driver.findElement(By.xpath("//*[@id='slider']"));
WebElement sometext = driver.findElement(By.xpath("//*[@id='content']/p[1]"));
System.out.println(sometext.getText());
System.out.println(scroll.isDisplayed());
/*Actions act = new Actions(driver);
int x = scroll.getLocation().x;
act.clickAndHold(scroll).dragAndDropBy(scroll, x, 300).build().perform();*/

/*JavascriptExecutor je = (JavascriptExecutor) driver;
je.executeScript("arguments[0].scrollIntoView(true);",scroll);*/

}

}


----------------------------------------- ###################
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='slider']"}
Command duration or timeout: 15 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'PUNsgomes0MFVH7.local', ip: '192.168.1.4', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=45.0.1, platform=MAC, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 948b3870-5b18-124e-87ac-879779783221
*** Element info: {Using=xpath, value=//*[@id='slider']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:500)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
at Slider.main(Slider.java:24)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='slider']"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.52.0', revision: '4c2593c', time: '2016-02-11 19:03:33'
System info: host: 'PUNsgomes0MFVH7.local', ip: '192.168.1.4', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_60'
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///var/folders/fz/txbyqp7x23scx0k5w3xy90pm0000gn/T/anonymous1656631884081195905webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10723)
at <anonymous class>.FirefoxDriver.prototype.findElement(file:///var/folders/fz/txbyqp7x23scx0k5w3xy90pm0000gn/T/anonymous1656631884081195905webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10732)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///var/folders/fz/txbyqp7x23scx0k5w3xy90pm0000gn/T/anonymous1656631884081195905webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12614)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///var/folders/fz/txbyqp7x23scx0k5w3xy90pm0000gn/T/anonymous1656631884081195905webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12619)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///var/folders/fz/txbyqp7x23scx0k5w3xy90pm0000gn/T/anonymous1656631884081195905webdriver-profile/extensions/fxdriver@googlecode.com/components/command-processor.js:12561)

M
Replied on 05/04/2016

there is no slider in the website.