Upload file to WatiN

  • How to upload a file using WatiN?
  • Is it possible for this file to be on a web server (as opposed to it on a user machine)?

A very useful piece of code. Thank.

+3
source share
1 answer

The file must be accessible to the client browser. This means that it must either be on the client machine or accessible through a share. If you want to store files in a central location, use a shared folder or create a way to copy the file to the client when you need it.

Regarding file download, it depends on how you should do it. If it uses a standard file input tag, it will work as follows:

HTML snippet:

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

the 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();
}
+12
source

Source: https://habr.com/ru/post/1729061/


All Articles