无法使用http://www.dropzonejs.com上的python selenium webdriver上传文件 [英] Unable to upload file using python selenium webdriver on http://www.dropzonejs.com

查看:112
本文介绍了无法使用http://www.dropzonejs.com上的python selenium webdriver上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用selenium web驱动上传文件。我得到文件上传对话框在MacOS和Windows中打开,之后没有任何反应。想知道为什么硒不通过上传对话框打开文件?

我使用的Webdriver命令:

<$ p $点击()
wd.get(http://www.dropzonejs.com/)
wd.find_element_by_css_selector(div.dz-message)。点击()
elm = wd.find_element_by_xpath(//输入[@ type ='file'])
elm.send_keys(input.dz-hidden-input /Users/bg/Downloads/YOURFILE.PDF)
elm.submit()


解决方案不要点击文件 input 元素 - 它会触发一个文件上传对话框,通过。将密钥发送到输入提交形式:

< pre $ elm = wd.find_element_by_xpath(//输入[@ type ='file'])
elm.send_keys(/ Users / bg / Downloads / myfile.PDF )
elm.submit()

submit()在这种情况下在输入元素上调用 - selenium 会找到相应的输入元素形式并提交。


I am attempting to upload a file using selenium web driver. I get the file upload dialogue box to open in both MacOS and Windows, after which nothing happens. Wondering why selenium does not open the file via the upload dialog?

Webdriver commands I am using:

wd.get("http://www.dropzonejs.com/")
wd.find_element_by_css_selector("div.dz-message").click()
wd.find_element_by_css_selector("input.dz-hidden-input").click()
elm = wd.find_element_by_xpath("//input[@type='file']")
elm.send_keys("/Users/bg/Downloads/YOURFILE.PDF")
elm.submit()

解决方案

Don't click the file input element - it would trigger a file upload dialog which you cannot control via selenium. Send the keys to the input and submit the form:

elm = wd.find_element_by_xpath("//input[@type='file']")
elm.send_keys("/Users/bg/Downloads/myfile.PDF")
elm.submit()

submit() in this case is called on an input element - selenium would find the corresponding to the input element form and submit it.

这篇关于无法使用http://www.dropzonejs.com上的python selenium webdriver上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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