I'm trying to build an app that uploads files to several sites (with the possibility of add more sites at any time). For this, I'm using Python with Selenium but I can't find a way to setup an drag and drop event/action. I just want to drag a local file and drop it on an HTML element (like a div or a form) to upload it. I've find a way to do it with this site but it just works with it because it triggers a specific JavaScript's function.
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load
jQuery.noConflict();
myOwnInput = window.jQuery('<input id="myOwnInput" type="file" />').appendTo('body');
function simulateDrop() {
var fileInput = document.getElementById('myOwnInput'),
file = fileInput.files[0];
holder.ondrop({
dataTransfer: { files: [ file ] },
preventDefault: function () {}
});
};
// Now I select a file with the input that I just added and then I execute the next line
simulateDrop();
That code it's not mine, I put together parts of code of (from here and here) because I don't know Javascript, but if it is necessary to do a drag and drop function for several sites, I can learn it with no problem. At the moment I think I can do it for each site studying how each one implement the drag and drop thing, but as I said, I will have to learn JavaScript and I don't know if there is a better way to achieve my goal. So I'm looking for a effective way to do the drag and drop action for several sites, preferably with Python but it is no exclusive.
For example, I tried to do it with uploadfiles.io but I can't make it work.
To summarize, what I need is advice on how to do the drag and drop action for files on different websites.