if
(allChildlinks !=
null
)
{
HtmlAnchor anchor = allChildlinks[0];
combinedFileName = downloadPath + anchor.InnerText;
anchor.Download(
false
, DownloadOption.Save, combinedFileName, 200000);
}
4 Answers, 1 is accepted
Please try using our DownloadsDialogHandler as shown at the bottom of that page instead. It handles the download dialogs across all browsers.
Regards,Anthony
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Note I am not using the default file download path. To get this to work in safari I had to set the download path in the browser settings to the directory that I wanted to use.
This is the full code of the step:
[CodedStep(@
"Find and Download File"
)]
public
void
DownloadDoc_CodedStep()
{
string
combinedFileName =
""
;
string
downloadPath = @
"C:\temp\SmokeTestDownloads\"
;
HtmlDiv sectionDiv = Pages.Vault.Find.ById<HtmlDiv>(
"section"
);
sectionDiv.Refresh();
HtmlDiv contentDiv = sectionDiv.Find.ByAttributes<HtmlDiv>(
"class=content"
);
HtmlTable records = contentDiv.Find.ByAttributes<HtmlTable>(
"class=records"
);
while
(records ==
null
|| records.Rows.Count == 0)
{
contentDiv.Refresh();
records = sectionDiv.Find.ByAttributes<HtmlTable>(
"class=records"
);
}
records.Refresh();
System.Collections.ObjectModel.ReadOnlyCollection<HtmlAnchor> allChildlinks = records.Find.AllByAttributes<HtmlAnchor>(
"class=filename"
);
if
(allChildlinks !=
null
)
{
Desktop desktop =
new
Desktop();
HtmlAnchor anchor = allChildlinks[0];
combinedFileName = downloadPath + anchor.InnerText;
DownloadDialogsHandler handler =
new
DownloadDialogsHandler(ActiveBrowser, DialogButton.SAVE, combinedFileName, desktop);
//anchor.Download(false, DownloadOption.Save, combinedFileName, 200000);
anchor.Click();
handler.WaitUntilHandled(200000);
}
SetExtractedValue(
"combinedfileName"
, combinedFileName);
}
Also on the document page it would be good to note that there needs to be a reference to the ArtOfTest.WebAii.Win32.Dialogs namespace in the test. Also the desktop object needs to be declared.
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 code will work in Safari, just not the custom path portion. The file will save to the default location.
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, see below for a work-around using a right mouse click and key presses to make that selection and then type in the custom path.
I saw the same behavior you described with Chrome, and I'm currently researching the extent of our support for download dialogs in code for that browser. In the meantime you can employ the same work-around as with Safari:
Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.DoNotHandle;
Manager.LaunchNewBrowser(BrowserType.Chrome);
ActiveBrowser.NavigateTo(
"http://databases.about.com/od/tutorials/a/excelsample.htm"
);
HtmlAnchor dlLink = Find.ByContent<HtmlAnchor>(
"Sample Address File"
);
dlLink.MouseClick(MouseClickType.RightClick);
System.Threading.Thread.Sleep(1000);
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);
Greetings, Anthony
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.