1

I'm trying to upload files on a website which using dropzone.js for file uploads. I've found the file upload field in form, but the script stops without throwing any error. I've also used find_elements_by_id("upload-input") to make sure there are not multiple fields with same id.

elem = driver.find_element_by_id("upload-input")
driver.implicitly_wait(2)
elem.send_keys("C:\KVR.pdf")

This is how html looks like:

 <div id="fallback" style="display: none;">
    <input id="upload-input" type="file" name="file" multiple="multiple">
    <div id="upload-progress" class="upload-progress"></div>
  </div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

As per the HTML you have shared the <input> tag is having style set to display: none;. You can use the following code block to upload the file :

element = driver.find_element_by_xpath("//div[@id='fallback']")
driver.execute_script("arguments[0].removeAttribute('style')", element)
driver.find_element_by_xpath("//input[@id='upload-input']").send_keys("C:\\KVR.pdf")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

DropzoneJS hides the <input type="file"> You can find those with the instruction below:

 dz_inputs = driver.find_elements(By.XPATH, "//input[@type='file' and @class='dz-hidden-input']")

Then for example, to add a file to the first dropzone on the page, you should proceed as below:

dz_inputs[0].send_keys("/File/path/file_name.extension")
Patrick
  • 1,091
  • 1
  • 14
  • 14