Unable to Handle the Download Dialog in Firefox, Chrome and Safari

9 posts, 1 answers
  1. Emily
    Emily avatar
    8 posts
    Member since:
    Jan 2012

    Posted 08 Jan 2012 Link to this post

    Hi all,
    Download dialog works fine with IE, but I cannot get it with Firefox, Chrome and Safari. It cannot save the file with the following code as below:

    //launch
                     BROWSER = MANAGER.ActiveBrowser; FFOpenDownloadDialog ffdownload = new FFOpenDownloadDialog(                         BROWSER,                         DialogButton.SAVE,                         Desktop);                         MANAGER.DialogMonitor.AddDialog(ffdownload);                         MANAGER.DialogMonitor.Start();         //Invoke the dialog                        BrowserNavigateTo(strURL);                         //save                         BROWSER = MANAGER.ActiveBrowser;                         SaveAsDialog saveas = new SaveAsDialog(                             BROWSER,                             DialogButton.SAVE, strFileLocation, MANAGER.Desktop);                         MANAGER.DialogMonitor.AddDialog(saveas);                         MANAGER.DialogMonitor.Start(); Please help. Thanks, Emily
  2. Emily
    Emily avatar
    8 posts
    Member since:
    Jan 2012

    Posted 09 Jan 2012 Link to this post

    Hi All,

    I add the below code at the beginning, and it works only with Firefox, but Chrome

    SM2Utilities.GlobalObject.MANAGER.Settings.UnexpectedDialogAction = ArtOfTest.WebAii.Core.UnexpectedDialogAction.DoNotHandle; //new - ok
    

    P.S: Safari doesn't allow us to enter file path. Therefore, I think we cannot handle download for Safari. 

    Please help if you guys are successful in download dialog on Chrome.

    Thanks,
    Emily
  3. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 11 Jan 2012 Link to this post

    Hello Emily,

    The following code works for me in IE, Firefox, and Chrome. It was written against a public site so please try it:

    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
     
    DownloadDialogsHandler handler = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, @"C:\address.xls", Desktop);
     
    HtmlAnchor dlLink = Find.ByContent<HtmlAnchor>("Sample Address File");
    dlLink.Click();
     
    handler.WaitUntilHandled(30000);

    You are correct about Safari; when clicking a download link it will automatically save the file to the default path you specify in its settings. So, the above code will work in Safari, just not the custom path portion. The file will save to the default location set in Safari.

    The only way to specify a custom save location in Safari is to right click the download link and choose "Download Linked File As...". If you want to specify a custom download path at run-time in Safari, here's a work-around using a right mouse click and key presses to make that selection and then type in the custom path:

    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    Manager.LaunchNewBrowser(BrowserType.Safari);
     
    HtmlAnchor dlLink = Find.ByContent<HtmlAnchor>("Sample Address File");
    dlLink.MouseClick(MouseClickType.RightClick);
     
    Manager.Desktop.KeyBoard.KeyPress(Keys.Down);
    Manager.Desktop.KeyBoard.KeyPress(Keys.Down);
    Manager.Desktop.KeyBoard.KeyPress(Keys.Down);
    Manager.Desktop.KeyBoard.KeyPress(Keys.Down);
    Manager.Desktop.KeyBoard.KeyPress(Keys.Enter);
     
    System.Threading.Thread.Sleep(3000);
    Manager.Desktop.KeyBoard.TypeText("C:\\address.xls", 10);
    Manager.Desktop.KeyBoard.KeyPress(Keys.Enter);

    Kind regards,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Emily
    Emily avatar
    8 posts
    Member since:
    Jan 2012

    Posted 12 Jan 2012 Link to this post

    Hi Anthony,

    Thank you very much. It works now on both Chrome and Safari as well.

    Thanks again for quick support.

    Emily 
  5. Emily
    Emily avatar
    8 posts
    Member since:
    Jan 2012

    Posted 12 Jan 2012 Link to this post

    Hi Anthony,

    I get another issue when running one test with multiple browser continuously (IE -> FF). It is able to download file for IE, then close IE browser. The new browser of FF is opened, then go to download part, error occurs. Please find attachment for the detail.

    Please help.

    Thanks,
    Emily
  6. Nitin
    Nitin avatar
    29 posts
    Member since:
    Oct 2010

    Posted 12 Jan 2012 Link to this post

    Hi Emily

    I am doing the same thing for IE 9 and getting this kind of Error while Debugging

    Please let me know if you have resolution for the same

    Thanks
    Nitin

  7. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 12 Jan 2012 Link to this post

    Hello Emily & Nitin,

    I encountered an issue if I tried to reuse the same download link and handler for the second browser. Once I defined them as new variables, it worked:

    Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
    Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
     
    DownloadDialogsHandler handler = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, @"C:\address.xls", Desktop);
     
    HtmlAnchor dlLink = Find.ByContent<HtmlAnchor>("Sample Address File");
    dlLink.Click();
     
    handler.WaitUntilHandled(30000);
     
    ActiveBrowser.Close();
     
    Manager.LaunchNewBrowser(BrowserType.FireFox);
     
    DownloadDialogsHandler handler2 = new DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, @"C:\address2.xls", Desktop);
     
    HtmlAnchor dlLink2 = Find.ByContent<HtmlAnchor>("Sample Address File");
    dlLink2.Click();
     
    handler2.WaitUntilHandled(30000);

    If you continue to have difficulty, please provide your code so I can test it directly and troubleshoot it.

    Greetings,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Emily
    Emily avatar
    8 posts
    Member since:
    Jan 2012

    Posted 13 Jan 2012 Link to this post

    Hi Anthony,

    I am also pass your code now. However, I got my trouble because I used kill process function for Safari after running all tests to close remaining Safari download browsers that couldn't been handled. 

    //Close all browser
                System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName(strBROWSER);
                foreach (System.Diagnostics.Process ProcessOfBrowser in process)
                {
                    ProcessOfBrowser.Kill();
                }


    Please help this case.
    Thanks,
    Emily
  9. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 13 Jan 2012 Link to this post

    Hello Emily,

    Presumably you're using that code to close the Safari Downloads mini-window. I think it's best to stick with ActiveBrowser.Close() for the main window and a series of key presses to close the Download window:

    Manager.Desktop.KeyBoard.KeyDown(Keys.Alt);
    Manager.Desktop.KeyBoard.KeyPress(Keys.F4);
    Manager.Desktop.KeyBoard.KeyUp(Keys.Alt);
    ActiveBrowser.Close();

    You may need to strategically place fixed delays before and/or after so execution is timed correctly:

    System.Threading.Thread.Sleep(1000);

    Regards,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top