华廷文件上传 [英] WatiN File Upload
问题描述
我已经遇到了障碍。我想使用华廷要上传的文件。我可以加载上传框,但很快消失。我的code,此刻的最后一行是:
I've hit a snag. I am trying to use WatiN to upload a file. I can load the upload box, but it quickly disappears. The last line of my code at the moment is:
ie.FileUpload(Find.ById("profile_file")).Click();
它加载的对话框中选择一个图片,但消失。是否有可能自动设置框的例子,负载的道路?C:/Desktop/image.jpg
It loads the dialog to select a picture but disappears. Is it possible to set the path of the box automatically example, load "C:/Desktop/image.jpg"?
此外,是否有可能要等上载完成后再继续?
Also, is it possible to wait for the upload to complete before continuing?
帮助是非常AP preciated。
Help is much appreciated.
感谢。
推荐答案
作为一种安全措施,浏览器不允许脚本设置文件输入的值。试想一下,如果他们做到了,我可以把一个隐藏的文件输入在我的网页,我有一个接触的形式,并将其值设置为C:未经用户许可\ topsecretinfo.txt。那么当用户提交表单,瞧,我有自己的绝密信息。
As a security measure, browsers don't allow scripts to set the value of a file input. Imagine if they did, I could put a hidden file input on my page where I have a contact form, and set its value to c:\topsecretinfo.txt without the user's permission. then when the user submits the form, voilà, I'd have their top secret information.
幸运了吧,今天我就遇到了这个问题,这是我做过什么来解决它:
As luck has it, I ran into this issue today and this is what I did to get around it:
- 在所谓的testupload页面上创建一个新的隐藏字段。
- 使用华廷这个隐藏字段的值设置为路径,以我的测试 文件
- 在服务器端,我检查这个领域,如果存在的话, 而不是读文件的发布,我从我的本地读取该文件 机。
- created a new hidden field on the page called "testupload".
- used Watin to set the value of this hidden field to the path to my test file
- on the server side, I check for this field and if it exists, instead of reading the posted file, I read this file from my local machine.
这篇关于华廷文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!