Skip to content

Instantly share code, notes, and snippets.

@adiroiban
Last active June 29, 2019 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adiroiban/212d61d7cc25a7719d6fc8bc33d702f9 to your computer and use it in GitHub Desktop.
Save adiroiban/212d61d7cc25a7719d6fc8bc33d702f9 to your computer and use it in GitHub Desktop.
Script to add a file to dropzone via Selenium... from Python
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')
@voidspace
Copy link

Does content need base64 encoding?

@pscheit
Copy link

pscheit commented Jun 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment