I've attempted to create a drag and drop simulation for Selenium WebDriver test using the following JavaScript code, but I keep encountering a WebDriver error. I opted for this approach because the Actions class didn't work on any browser (Firefox, Chrome). Can anyone point out what might be going wrong?
String filePath = "C://Work//Spica import files//drag_and_drop_helper.js";
String source = "li[draggable='true']";
String target = "#fieldCc";
StringBuffer buffer = new StringBuffer();
String line;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(filePath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
while((line = br.readLine())!=null)
buffer.append(line);
} catch (IOException e) {
e.printStackTrace();
}
String javaScript = buffer.toString();
javaScript = javaScript + "$('" + source + "').simulateDragDrop({ dropTarget: '" + target + "'});";
((JavascriptExecutor)getDriver()).executeScript(javaScript);
The error message reads as follows:
org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: missing ) after argument list (Session info: chrome=53.0.2785.116) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 17 milliseconds Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09' System info: host: 'EN610188', ip: '172.16.116.151', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_91' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=C:\Users\lgrecu\AppData\Local\Temp\scoped_dir5352_12600}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=53.0.2785.116, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: fe314c5e2184e76f1b3d934159ae2887 Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09' System info: host: 'EN610188', ip: '172.16.116.151', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_91' Driver info: driver.version: unknown