I have been working on automating my Salesforce application using Selenium and incorporating JavaScript for drag and drop functionality. However, I am facing an issue where the element I drop onto the target ends up being positioned elsewhere. Manually holding the element on the target for a few seconds seems to correct this problem. Is there a way to include code that will hold the element on the target for a specific duration?
Below is the code snippet that successfully handles drag and drop actions for me. How can I modify it to ensure the source element is held on the target?
final String java_script =
var src=arguments[0],tgt=arguments[1];
var dataTransfer={dropEffect:'',effectAllowed:'all',files:[],items:{},types:[],setData:function(format,data){this.items[format]=data;this.types.append(format);},getData:function(format){return this.items[format];},clearData:function(format){}};
var emit=function(event,target){
var evt=document.createEvent('Event');
evt.initEvent(event,true,false);
evt.dataTransfer=dataTransfer;
target.dispatchEvent(evt);
};
emit('dragstart',src);
emit('dragenter',tgt);
emit('dragover',tgt);
emit('drop',tgt);
emit('dragend',src);
emit('dragleave' , src);
((JavascriptExecutor)driver).executeScript(java_script, src, tgt);
Thank you in advance for any assistance!