How to handle DownloadDialog in IE

4 posts, 1 answers
  1. San
    San avatar
    24 posts
    Member since:
    Apr 2011

    Posted 19 Jul 2011 Link to this post

    Hello,

    I am getting stuck while trying to get handle a Download Dialog in IE 8.

    My scenario is:
    . Lauching a web app1.
    . From that, clicking on an Anchor, it will launch another browser with a Download Dialog displayed there.

    I found out that most the examples and cases around this forum just mentions the Anchor to fire the Download Dialog inside the web app1 only, but my case is pretty difficult since it was automatically launched from another browser (I had 2 browsers after clicking on the Anchor on the web app1)

    Does anyone have any idea to help me out?

    Regards,
    San

    What I've tried:

    try
            {
                Utilities.GlobalObject.BROWSER = Utilities.GlobalObject.MANAGER.ActiveBrowser;
                 
                HtmlAnchor cphPageContent_btnExport = Utilities.GlobalObject.BROWSER.Find.ByAttributes<HtmlAnchor>("href=trend_charts.aspx?output=xls");
                cphPageContent_btnExport.Click();
                Utilities.GlobalObject.BROWSER.WaitUntilReady();
                Utilities.GlobalObject.BROWSER = Utilities.GlobalObject.MANAGER.ActiveBrowser;
                DownloadDialogsHandler handler = new DownloadDialogsHandler(Utilities.GlobalObject.BROWSER, DialogButton.SAVE, saveLocation, Utilities.GlobalObject.MANAGER.Desktop);
                handler.WaitUntilHandled(20000);
            }
            catch (Exception EX)
            {
                string strE = EX.ToString();
                Utilities.GlobalObject.LOGGER.log(strE);
            }
  2. Answer
    Cody
    Admin
    Cody avatar
    3354 posts

    Posted 19 Jul 2011 Link to this post

    Hello San,

    Does cphPageContent_btnExport.Click(); initiate the download? The problem may be that DownloadDialogsHandler handler = new DownloadDialogsHandler needs to be placed before the action that initiates the download. If the handler is created after the download has started, it's too late. The handler will only recognize and handle new download dialog windows once the handler is created.

    Also as a side note, this line:

    Utilities.GlobalObject.BROWSER.WaitUntilReady();

    is probably not needed. The .Click() call has a built in WaitUntilReady already.

    Regards,
    Cody
    the Telerik team
    Register today for a live 'What's New in Test Studio R1 2011 SP2' event on Tuesday, July 19 at 2pm EST!

    Have you looked at the new Online User Guide for Telerik Test Studio?
  3. San
    San avatar
    24 posts
    Member since:
    Apr 2011

    Posted 22 Jul 2011 Link to this post

    Thanks Cody for your reply and your adivse on the way using WaitUntilReady().

    I have changed my code as below and it works now. 

    But I still have 2 more concerns:
    1. Why do I have to invoke the popup dialog twice becuase I just keep the 2nd invoke only, it just launch the download dialog but can not click on Save and can not save the file. So I have to make it twice.
    2. I can not download TXT but XML, XLS works just fine.

    Can someone help me out?

    Cheers,
    San


    try
                {
                    //launch
                    Utilities.GlobalObject.BROWSER = Utilities.GlobalObject.MANAGER.ActiveBrowser;
                    IEDownloadDialog iedownload = new IEDownloadDialog(
                    Utilities.GlobalObject.BROWSER,
                    DialogButton.SAVE,
                    Utilities.GlobalObject.MANAGER.Desktop);
                    Utilities.GlobalObject.MANAGER.DialogMonitor.AddDialog(iedownload);
                    Utilities.GlobalObject.MANAGER.DialogMonitor.Start();
     
                    //Invoke the dialog
                    Utilities.GlobalObject.BROWSER.NavigateTo(Utilities.GlobalRunning.SERVER_URL + "trend_charts.aspx?output=txt");
     
                    //save
                    Utilities.GlobalObject.BROWSER = Utilities.GlobalObject.MANAGER.ActiveBrowser;
                    SaveAsDialog saveas = new SaveAsDialog(
                        Utilities.GlobalObject.BROWSER,
                        DialogButton.SAVE, saveLocation,
                        Utilities.GlobalObject.MANAGER.Desktop);
                      
                    Utilities.GlobalObject.MANAGER.DialogMonitor.AddDialog(saveas);
                    Utilities.GlobalObject.MANAGER.DialogMonitor.Start();
     
                    //Invoke the dialog
                    Utilities.GlobalObject.BROWSER.NavigateTo(Utilities.GlobalRunning.SERVER_URL + "trend_charts.aspx?output=txt");
                }
                catch { }
  4. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 25 Jul 2011 Link to this post

    Hi San,

    Our Unexpected Dialog Handler feature might be getting in your way. Try turning it off at the beginning of your test using code like this:

    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;

    To make the browser download .txt files instead of displaying them, your developers must add a Content-Disposition header to the output.
    Regards,
    Cody
    the Telerik team
    Register today for a live 'What's New in Test Studio R1 2011 SP2' event on Tuesday, July 19 at 2pm EST!

    Have you looked at the new Online User Guide for Telerik Test Studio?

    Content-Disposition

Back to Top