UnKnown777
UnKnown777

Reputation: 59

How to automate file download in IE11

It is possible to automate file download and save in IE if its version is 8 or below using the following code:

AutomateWinWindow objfileWindow;
AutomateWinWindow objfileSaveAs;

objfileWindow = new AutomateWinWindow("File Download", "#32770", "1", "File Download", "");
CodedUI_Automation.AutomateWinButton.AutomateWinButtonMethod(objfileWindow, "Save", "File Download", "Click");

objfileSaveAs = new AutomateWinWindow("Save As", "#32770", "1", "Save As", "");
templatesourcefile = ManageSaveAsWindow(objfileSaveAs, TemplateInputPath, offeringID, "Excel");            

But for the latest versions file download window is not coming. Its coming as a small pop up in the down without any name and id. It will be a great help if someone can help me in this.

Upvotes: 1

Views: 1314

Answers (1)

MPavlak
MPavlak

Reputation: 2221

The code you have supplied does not look like plain coded ui to me. Please also supply the class definitions for the AutomateWinWindow and ManageSaveAsWindow.

It is definitely possible to handle the save of a file. I would recommend two things.

  1. You can use the inspector from Coded UI tools to inspect the things you want to click on or manipulate.

  2. You can use an inspector like the Inspect tool.

Normally I'd also recommend using record and play just to see what it figures out, but seems like record and play does not work for this (at least not on my machine).

Using the built in inspect tool, I can see that the notification toolbar has the following properties:

ControlType: ToolBar
TechnologyName: MSAA
Name: Notification

Using the navigation arrows in the inspector, you can move to children or sibling elements.

I was able to spy the UISaveSplitButton that can be used to save the file.

ControlType: SplitButton (important! not a button, but a split button)
TechnologyName: MSAA
Name: Save

Using a searching abstraction like CodedUI Fluent (something I wrote, similar to CUITe), it would look like:

WinToolBar notificationBar = browserWindow.Find<WinToolBar>(WinToolBar.PropertyNames.Name, "Notification", PropertyExpressionOperator.EqualTo);

WinSplitButton saveButton = notificationBar.Find<WinSplitButton>(WinButton.PropertyNames.Name, "Save", PropertyExpressionOperator.EqualTo);

saveButton.Click();

Using only CodedUI, it would look like this (I prefer the fluent searching syntax from the above abstraction, but for completeness):

WinToolBar notificationBar = new WinToolBar(browserWindow);
notificationBar.SearchProperties.Add(WinToolBar.PropertyNames.Name, "Notification", PropertyExpressionOperator.EqualTo);

WinSplitButton saveButton = new WinSplitButton(notificationBar);
saveButton.SearchProperties.Add(WinButton.PropertyNames.Name, "Save", PropertyExpressionOperator.EqualTo);

Mouse.Click(saveButton);

Upvotes: 1

Related Questions