Selenium 3.141
Support for Chrome and Firefox browsers
Attempting to perform a drag-and-drop operation between two fields on a web application using Selenium. The drag/drop fields are highlighted, indicating the correct selection, but despite some action such as scrollbar movement, the object does not actually get dropped.
WebElement source = fromfield.findElement(By.xpath(".//*[contains(@title,'task1')]"));
WebElement tofield = driver.findElement(By.xpath("//*[contains(@data-field-name,'task2')]"));
highlight(source)
highlight(tofield) //both dragdrop fields get highlighted
Actions maction=new Actions(driver);
maction.dragAndDrop(source, tofield).build().perform();
//Tried an alternative method of drag and drop by adjusting pause duration with no success
maction.clickAndHold(source).pause(2000).moveToElement(tofield).pause(2000).release().build().perform();
Expected Outcome: Successful Drag-Drop operation between the fields
Actual Result: Fields highlight during the drag/drop actions, but the object is not successfully dropped.
After suggestions from Infern0, attempted the following code snippet but encountered an exception.
String js_filepath = "C:/test/drag_and_drop_helper.js";
String java_script = null;
String text = null;
BufferedReader input = new BufferedReader(new FileReader(js_filepath));
StringBuffer buffer = new StringBuffer();
while ((text = input.readLine()) != null)
buffer.append(text + " ");
java_script = buffer.toString();
jse.executeScript(java_script+"$('#{objectProperty_c77}').simulateDragDrop({ dropTarget: '#{objectProperty_c76}'});");
JavaScript reference: https://gist.github.com/rcorreia/2362544#file-drag_and_drop_helper-js
Exception: org.openqa.selenium.JavascriptException: SyntaxError: unexpected token: identifier