如何使用style =“" display:none;"在dropzone.js上上传文件;使用硒? [英] How can i upload files on dropzone.js with style="display: none;" using Selenium?

查看:95
本文介绍了如何使用style =“" display:none;"在dropzone.js上上传文件;使用硒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在使用dropzone.js进行文件上传的网站上上传文件. 我在表单中找到了文件上载字段,但是脚本停止了,没有引发任何错误. 我还使用了find_elements_by_id("upload-input")来确保没有多个具有相同ID的字段.

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

这是html的样子:

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

推荐答案

根据 HTML ,您共享了<input>标签的 style 设置为显示:无; .您可以使用以下代码块上传文件:

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

这篇关于如何使用style =“&quot; display:none;&quot;在dropzone.js上上传文件;使用硒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆