Download a file using Watin

How can I upload a file using watin? I searched and tried a lot, but I can’t get it. I just want to click the link that has the download and save it. I used examples that I found, but to no avail. The problem is that I use "WaitUntilFileDownloadDialogIsHandled (15)", but a 15 second pass, as well as an exception and an exception: WatiN.Core.Exceptions.WatiNException: the dialog is not displayed after 15 seconds.

This is the code:

FileDownloadHandler download = new FileDownloadHandler("C:/Development/Test/Downloads/" + "excel" + ".xls");
            using (new UseDialogOnce(browser.DialogWatcher, download))
            {
                browser.Button(Find.ById("id_of_the_button")).ClickNoWait();
                download.WaitUntilFileDownloadDialogIsHandled(15);
                download.WaitUntilDownloadCompleted(150);                
                browser.RemoveDialogHandler(download);
            }

Please, help!

+3
source share
3 answers

I discovered one problem that tormented me

FileDownloadHandler handler = new FileDownloadHandler(@"c:\temp\file.csv");
browser.DialogWatcher.CloseUnhandledDialogs = false;
using (new UseDialogOnce(browser.DialogWatcher, handler))
{
    browser.Link(Find.ByText("July2011")).Click();
    handler.WaitUntilFileDownloadDialogIsHandled(15);
    handler.WaitUntilDownloadCompleted(240);
}

"CloseUnhandledDialogs = false". " " , , .

+2

,

FileDownloadHandler download = new FileDownloadHandler("C:\\Development\\Test\\Downloads\\" + "excel" + ".xls");
browser.AddDialogHandler(download);
browser.Button(Find.ById("id_of_the_button")).ClickNoWait();
download.WaitUntilFileDownloadDialogIsHandled(15);
download.WaitUntilDownloadCompleted(150);                
browser.RemoveDialogHandler(download);

, , , escape- DialogHandler .

~

0

Downloading documents using WATIN

 public FileDownloadHandler fileDownloadHandler;

 /*CLICK ON THE FILE LINK TO DOWNLOAD..IT WILL PROMPT FOR FILE DOWNLOAD DIALOG..TO HANDLE THAT DIALOG USE THE BELOW CODE*/

  fileDownloadHandler = new FileDownloadHandler(//THE PATH IN WHICH YOU DOWNLOAD DOCUMENTS//);
    try
    {
        using (new UseDialogOnce(ie.DialogWatcher, fileDownloadHandler))
        {                                               
          download();
        }            
    }
    catch (WatiN.Core.Exceptions.WatiNException ex)
    {
      download();
    }
    public void download()
    {
         try
        {
            fileDownloadHandler.WaitUntilDownloadCompleted(8);
        }
        catch (WatiN.Core.Exceptions.WatiNException ex)
        {
            download();
        }
    }
0
source

All Articles