如何上传文件(图片)与硒,蟒蛇 [英] How to upload file ( picture ) with selenium, python

查看:129
本文介绍了如何上传文件(图片)与硒,蟒蛇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能用selenium测试工具上传网页图片?我正在使用Python。



我尝试了很多东西,但没有任何工作。我很绝望。

上传看起来像这样:

http://img21.imageshack.us/img21/1954/uploadgr.jpg



感谢您的帮助

Filip。

解决方案

上传输入控件打开一个本地对话框(这是由浏览器完成的),所以点击控件或通过Selenium浏览按钮将弹出对话框,测试将挂起。



解决方法是通过JavaScript设置上传输入的值(在Java中是通过JavascriptExecutor完成),然后提交表单。

请参阅

is there any possibility how to upload on web picture with selenium testing tool ? I am using python.

I tryed many things, but nothing didnt work. I am desperate.

Upload looks like this :

http://img21.imageshack.us/img21/1954/uploadgr.jpg

Thank you for your help

Filip.

解决方案

Upload input control opens a native dialog (it is done by browser) so clicking on the control or browse button via Selenium will just pop the dialog and the test will hang.

The workaround is to set the value of the upload input via JavaScript (in Java it is done via JavascriptExecutor) and then submit the form.

See this question for sample in C#, I am sure there's also a way to call JavaScript in Python but I never used Selenium Python bindings

这篇关于如何上传文件(图片)与硒,蟒蛇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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