Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Nov 22, 2018

Does content need base64 encoding?

@pscheit

This comment has been minimized.

Copy link

commented Jun 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.