Is there a way to achieve drag and drop for Magento image upload using Selenium?
Probably duplicate of below
Python with Selenium: Drag and Drop from file system to webdriver?
JS_DROP_FILE = """
var target = arguments[0],
offsetX = arguments[1],
offsetY = arguments[2],
document = target.ownerDocument || document,
window = document.defaultView || window;
var input = document.createElement('INPUT');
input.type = 'file';
input.onchange = function () {
var rect = target.getBoundingClientRect(),
x = rect.left + (offsetX || (rect.width >> 1)),
y = rect.top + (offsetY || (rect.height >> 1)),
dataTransfer = { files: this.files };
['dragenter', 'dragover', 'drop'].forEach(function (name) {
var evt = document.createEvent('MouseEvent');
evt.initMouseEvent(name, !0, !0, window, 0, 0, 0, x, y, !1, !1, !1, !1, 0, null);
evt.dataTransfer = dataTransfer;
target.dispatchEvent(evt);
});
setTimeout(function () { document.body.removeChild(input); }, 25);
};
document.body.appendChild(input);
return input;
"""
def drag_and_drop_file(drop_target, path):
driver = drop_target.parent
file_input = driver.execute_script(JS_DROP_FILE, drop_target, 0, 0)
file_input.send_keys(path)
See below thread as well
Selenium: Drag and Drop from file system to WebDriver?
How to simulate HTML5 Drag and Drop in Selenium Webdriver?
The interim solution to my problem is AutoIt.
Big thanks to @KunduK How to upload image with angular components using python selenium
I targeted the xpath of the image upload area then autoit did the rest with the code below:
autoit.win_wait_active("File Upload",5)
if autoit.win_exists("File Upload"):
autoit.control_send("File Upload","Edit1",filepath+"{ENTER}")```