Uploading File in WatiN
- 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)?
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();
}
精彩评论