当文件输入被隐藏时如何使用Selenium上传文件? [英] How to upload file using Selenium when the file input is hidden?
问题描述
我试图在一个现代化的网页上自动化文件上传,在旧的< input type =file> $ c上面使用了一些奇特的拖放操作$ C>。元素仍然在页面上,但Selenium不能使用它 - 我得到着名的元素是目前不可见的和所以不得与
错误进行交互。我想我有两个选择:
$ b $ ol
jQuery(... ).show()
对此没有帮助,我不太确定为什么F12工具报告元素是可见的,但是Selenium仍然认为它不是(并且,被告知的真实性无法看到文件字段,F12工具只是突出显示页面上的一个矩形区域)< input type =file>的值;
通过JavaScript,但我得到各种安全错误(试过火狐浏览器和Chrome)。我做了吗?理想情况下,无论元素是否可见,都会强制Selenium执行该操作,但是我不认为这是可能的,是吗?
>解决方案使用替代方法来隐藏文件输入,例如: 绝对定位离线 绝对定位+剪贴簿:rect 引用
$ b
- > Blueimp文件上传没有发生在IE 8
I'm trying to automate file upload on a modern web page that uses some fancy drag&drop upload panel on top of the old <input type="file">
. The element is still on the page but Selenium can't use it - I get the famous
"Element is not currently visible and so may not be interacted with"
error. I think I've got two options:
- Make the element somehow visible - but calling
jQuery(...).show()
on it doesn't help, I'm not quite sure why F12 tools report the element as visible but Selenium still thinks it isn't (and, truth to be told, I can't see the file field either, F12 tools just highlight a rectangular area on the page) - Set the value of
<input type="file">
via JavaScript but I get all sorts of security errors (tried Firefox and Chrome).
What can I do about it? Ideally, there would be a way to force Selenium to carry out the action no matter if the element is visible or not but I don't think it's possible, is it?
Use an alternative method to hide the file input, such as:
absolute positioning offscreen
absolute positioning + clip:rect
then it will work.
References
In JavaScript can I make a "click" event fire programmatically for a file input element?
file input javascript click generated not from a real mouse click chrome
这篇关于当文件输入被隐藏时如何使用Selenium上传文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!