Last active
          June 29, 2019 10:19 
        
      - 
      
 - 
        
Save adiroiban/212d61d7cc25a7719d6fc8bc33d702f9 to your computer and use it in GitHub Desktop.  
    Script to add a file to dropzone via Selenium... from Python
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def addFileToDropzone(self, driver, css_selector, name, content): | |
| """ | |
| Trigger a file add with `name` and `content` to Dropzone element at `css_selector`. | |
| """ | |
| script = """ | |
| var dropzone_instance = Dropzone.forElement(css_selector) | |
| var new_file = new File(['%s'], '%s', {type: 'application/octet-binary'}) | |
| dropzone_instance.addFile(new_file) | |
| """ % (content, name) | |
| driver.execute_script(script) | |
| # Use it like | |
| self.addFileToDropzone('z-test.txt', b'file-content-here') | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Does content need base64 encoding?