2

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.

2
  • So in your case in place of drag and drop, if you have to upload a file, will that work? Commented Oct 11, 2017 at 6:45
  • @ShoaibAkhtar I don't understand what you mean. If I find a way to do the drag and drop action with files, I will be able to upload the files. As far as I could see, websites just require to drag and drop the file(s), and then the upload is automatic or I'have just to click a button (an easy task with Selenium). But the difficult part is to be able to drag and drop files on different websites. Commented Oct 11, 2017 at 15:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.