This is a migrated thread and some comments may be shown as answers.

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

8 Answers 151 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Emily
Top achievements
Rank 1
Emily asked on 09 Jan 2012, 04:39 AM
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

8 Answers, 1 is accepted

Sort by
0
Emily
Top achievements
Rank 1
answered on 09 Jan 2012, 10:30 AM
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
0
Accepted
Anthony
Telerik team
answered on 11 Jan 2012, 04:48 PM
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.
0
Emily
Top achievements
Rank 1
answered on 12 Jan 2012, 08:35 AM
Hi Anthony,

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

Thanks again for quick support.

Emily 
0
Emily
Top achievements
Rank 1
answered on 12 Jan 2012, 11:49 AM
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
0
Nitin
Top achievements
Rank 1
answered on 12 Jan 2012, 12:53 PM
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

0
Anthony
Telerik team
answered on 12 Jan 2012, 06:28 PM
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.
0
Emily
Top achievements
Rank 1
answered on 13 Jan 2012, 12:13 PM
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
0
Anthony
Telerik team
answered on 13 Jan 2012, 05:15 PM
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.
Tags
General Discussions
Asked by
Emily
Top achievements
Rank 1
Answers by
Emily
Top achievements
Rank 1
Anthony
Telerik team
Nitin
Top achievements
Rank 1
Share this question
or