如何在 IE11 中自动下载文件

How to automate file download in IE11

如果版本为8或以下,可以使用以下代码在IE中自动下载和保存文件:

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");            

但是最新版本的文件下载 window 不可用。它作为一个没有任何名称和 ID 的小弹出窗口出现。如果有人能在这方面帮助我,那将是一个很大的帮助。

您提供的代码在我看来不像纯编码 ui。还请提供 AutomateWinWindow 和 ManageSaveAsWindow 的 class 定义。

处理文件的保存是绝对可以的。我会推荐两件事。

  1. 您可以使用 Coded UI 工具中的检查器来检查要单击或操作的内容。

  2. 您可以使用 Inspect 工具之类的检查器。

通常我也建议使用录制和播放只是为了看看结果如何,但似乎录制和播放对此不起作用(至少在我的机器上不起作用)。

使用检查工具中的 built,我可以看到通知工具栏具有以下属性:

ControlType: ToolBar
TechnologyName: MSAA
Name: Notification

使用检查器中的导航箭头,您可以移动到子元素或同级元素。

我发现了可以用来保存文件的 UISaveSplitButton。

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

使用像 CodedUI Fluent (something I wrote, similar to CUITe) 这样的搜索抽象,它看起来像:

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

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

saveButton.Click();

仅使用 CodedUI,它看起来像这样(我更喜欢上面抽象的流畅搜索语法,但为了完整性):

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);