开发者

Uploading File in WatiN

开发者 https://www.devze.com 2022-12-17 00:40 出处:网络
How do I开发者_运维问答 upload a file using WatiN? Is it possible for this file to reside on a web server (as oppose to it being on user\'s machine)?
  1. How do I开发者_运维问答 upload a file using WatiN?
  2. Is it possible for this file to reside on a web server (as oppose to it being on user's machine)?

Code snippet is highly appreciated. Thanks.


The file needs to be accessible to the client browser. That means it either needs to be on the client machine or accessible through a share. If you want to store files in a central location, either use a shared folder, or come up with a way to copy the file to the client when you need it.

As for uploading the file, that is going to depend on how you have to do it. If it uses a standard file input tag, it would work like this:

HTML snippet:

<form action="upload.asp" method="post">
<input type="file" name="uploaded_file">
<input type="submit" name="submit_upload">
</form>

Code:

void UploadFile(string filepath, Browser browser)
{
  FileUpload upload = browser.FileUpload(Find.ByName("uploaded_file"));
  upload.Set(filepath);
  Button submit = browser.Button(Find.ByName("submit_upload"));
  submit.Click();
}
0

精彩评论

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