File download dialog doesn't work in IE9 (Windows7) NetFramework 4.0.
Following code snippet might help you resolve the issue:
First you must to add refernce UIAutomationClient and UIAutomationTypes to your test project.
After In Ie9 Tools -> View Downloads -> Options define path to your save folder.
The next method is extended Browser class
public static void DownloadIEFile(this Browser browser, FileDownloadHandler h)
{
// see information here (http://msdn.microsoft.com/en-us/library/windows/desktop/ms633515(v=vs.85).aspx)
Window windowMain = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(browser.hWnd, 5));
// if doesn't work try to gain sleep interval or write your own waitUntill method
Window windowDialog = WaitUntillWindowExsist(windowMain, 100);
Thread.Sleep(1000);
windowDialog.SetActivate();
System.Windows.Automation.AutomationElementCollection amc = System.Windows.Automation.AutomationElement.FromHandle(windowDialog.Hwnd).FindAll(System.Windows.Automation.TreeScope.Children
, System.Windows.Automation.Condition.TrueCondition);
foreach (System.Windows.Automation.AutomationElement element in amc)
{
// You can use "Save ", "Open", ''Cancel', or "Close" to find necessary button Or write your own enum
if (element.Current.Name.Equals("Save"))
{
// if doesn't work try to gain sleep interval or write your own waitUntill method
// WaitUntillButtonExsist(element,100);
Thread.Sleep(1000);
System.Windows.Automation.AutomationPattern[] pats = element.GetSupportedPatterns();
foreach (System.Windows.Automation.AutomationPattern pat in pats)
{
// '10000' button click event id
if (pat.Id == 10000)
{
System.Windows.Automation.InvokePattern click = (System.Windows.Automation.InvokePattern)element.GetCurrentPattern(pat);
click.Invoke();
}
}
} }
private static Window WaitUntillWindowExsist(Window window, int retrCount)
{
Window windowDialog = new Window(WatiN.Core.Native.Windows.NativeMethods.GetWindow(window.Hwnd, 5));
if (windowDialog.Exists() || retrCount < 1)
{
return windowDialog;
}
else
{
Thread.Sleep(1000);
retrCount--;
if (retrCount < 1)
{
throw new Exception("Download dialog can't be found.");
}
return WaitUntillWindowExsist(window, retrCount);
}
}
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
I can't get this to work for me at all. I have also tried the answer on http://stackoverflow.com/questions/7500339/how-to-test-file-download-with-watin-ie9 as this looks very similar but with no luck.
Is there going to be an actual watin fix for this?