Selenium - Drag and Drop
Question: I am looking to automate the dropping of a file from the desktop to the page
using Firefox as the browser, and Selenium on Python for automation.

Here is the code for the drag-and-drop on the page:

    
    
    <div id="dropbox">...</div>
    <script type="text/javascript"> ... 
       dropbox.addEventListener("drop", dropUpload, false);
    <script>
    
    ...
    
    function dropUpload(event) { 
    ... 
    files = event.dataTransfer.files;
    ...
    }
    

Most of the threads out there deal with dropping some other element besides a
file from the filesystem. The problem is that I need the event to contain a
file object with the actual data.

I've tried just typing into the dropbox element, as others have suggested, but
this obviously doesn't work with a div element.


Answer: This is very painful to do with Selenium alone. If using a commercial add-on
to Selenium is an option for you, you can try [Helium](http://heliumhq.com).
It lets you drag your file via the following code:

    
    
    from helium.api import drag_file
    drag_file(r"C:\Documents\notes.txt", to=driver.find_element_by_id("dropbox"))
    

Nicer still is if your `#dropbox` div contains some text, eg. `Drop files
here`. Then you can do

    
    
    drag_file(r"C:\Documents\notes.txt", to="Drop files here")
    

