开发者

WatiN File Upload

I've hit a snag. I am trying to use WatiN to upload a file. I can load the upl开发者_如何学JAVAoad box, but it quickly disappears. The last line of my code at the moment is:

ie.FileUpload(Find.ById("profile_file")).Click();

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?

Help is much appreciated.

Thanks.


This is 6 years late, but if anyone else (like me) is still having trouble with this, here's a solution.

To fill out the file dialogue, try this:

ie.FileUpload(Find.ById("profile_file")).Set("filename.txt");

This will automatically pull up the file dialogue. You'll then see text being automatically typed into the file selection textfield.

No need for any sendkeys.


While this won't answer your question directly, I suspect there is a DialogWatcher automatically canceling the dialog.


why do you need to select from the Dialog.. Try to just sent the Text:

ie.FileUpload(Find.ById("profile_file")).Text = "C:/Desktop/image.jpg";


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:

  • 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜