WatiN File Upload

蹲街弑〆低调 提交于 2019-12-11 01:55:58

问题


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();

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.


回答1:


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.




回答2:


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




回答3:


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";



回答4:


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.


来源:https://stackoverflow.com/questions/3065611/watin-file-upload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!