public void DownloadIEFile(Browser browser) { HwndSource source; source = HwndSource.FromHwnd(WatiN.Core.Native.Windows.NativeMethods.GetWindow(browser.hWnd, 5)); Window windowMain = source.RootVisual as Window; System.Windows.Automation.TreeWalker trw = new System.Windows.Automation.TreeWalker(System.Windows.Automation.Condition.TrueCondition); System.Windows.Automation.AutomationElement mainWindow = trw.GetParent(System.Windows.Automation.AutomationElement.FromHandle(browser.hWnd)); source = HwndSource.FromHwnd(WatiN.Core.Native.Windows.NativeMethods.GetWindow(new WindowInteropHelper(windowMain).Handle, 5)); Window windowDialog = source.RootVisual as Window; // if doesn't work try to increase sleep interval or write your own waitUntill method Thread.Sleep(1000); windowDialog.Activate(); System.Windows.Automation.AutomationElementCollection amc = System.Windows.Automation.AutomationElement.FromHandle(new WindowInteropHelper(windowDialog).Handle).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 increase sleep interval or write your own waitUntil method // WaitUntilButtonExsist(element,100); Thread.Sleep(1000); System.Windows.Automation.AutomationPattern[] pats = element.GetSupportedPatterns(); // replace this foreach if you need 'Save as' with code bellow 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(); } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)