Search code examples
c#asp.netwatin

How to download file with watin with out popUp dialogs


I need to download files with WatIn and i need to do this when windows is lock,that mean i can't use DownloadIeFile that will open the saveAs popUp insert path and save it is working when windows is open but i need to handle this saveAs finction with out save dialogs.

Any one know how to do this?

My code

  using (var browser = new IE("https://login.bank.com"))
            {
                try
                {
                    step = "1";
                    #region Login
                    browser.WaitForComplete();
                    try
                    {
                        //  browser.Visible = false;
                        browser.TextField(Find.ById("userID")).TypeText(strUser);
                        Thread.Sleep(1000);
                        browser.TextField(Find.ById("numID")).Value = strUserId;
                        browser.TextField(Find.ById("userPassword")).TypeText(strPass);
                        linkExist = browser.Image(Find.ById("inputSend")).Exists;
                        if (linkExist) browser.Image(Find.ById("inputSend")).Click();
                        browser.WaitForComplete();
                        linkExist = false;
                    }
                    catch (Exception ex)
                    {
                        successful = false;

                    }
                    browser.WaitForComplete();

//this wil open save dialog
 browser.GoToNoWait(DownloadLink);

//this will emulate clicks and press SaveAs that insert path and save it
 DownloadIeFile(browser, path);
//All works,BUT only if windows is open when it is on lock it dont hanlde it

}

Solution

  • Watin will not work when machine is locked. Since it uses, Microsoft.mshtml and Interop.SHDocVw binary references. These binaries are COM components and needs an interactive UI. For sample you can try out login itself instead of download. Start the test and lock the machine and then unlock. Observe the result, it will be failed throwing an error like COM exception....