How can i upload files on dropzone.js with style=“

2019-08-13 23:12发布

问题:

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>

回答1:

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")