コード例 #1
0
        /// <summary>
        /// Method to handle the IE9 File Download Notification Bar
        /// Uses UI Automation
        /// May want to add this as a dialog handler inheriting BaseDialogHandler
        /// </summary>
        /// <param name="name"></param>
        public void IE9FileDownload(string name)
        {
            UIAutomationClass uac = new UIAutomationClass();

            System.Windows.Automation.AutomationElementCollection test = uac.GetDeskTopChildren();
            foreach (System.Windows.Automation.AutomationElement x in test)
            {
                if (x.Current.ClassName.Equals("IEFrame"))
                {
                    // Console.Write(x.Current.ClassName + " " + x.Current.ControlType + " " + x.Current.AutomationId + " " + x.Current.ItemType + " " + x.Current.Name + Environment.NewLine);
                    System.Windows.Automation.AutomationElementCollection y = x.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                    foreach (System.Windows.Automation.AutomationElement z in y)
                    {
                        // Console.Write(x.Current.ClassName + " " + z.Current.ClassName + " " + z.Current.ControlType + " " + z.Current.AutomationId + " " + z.Current.ItemType + " " + z.Current.Name + Environment.NewLine);
                        if (z.Current.ClassName.Equals("Frame Notification Bar"))
                        {
                            System.Windows.Automation.AutomationElementCollection g = x.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                            foreach (System.Windows.Automation.AutomationElement bn in g)
                            {
                                // Console.Write("First Child" + "Class Name: " + bn.Current.ClassName + " " + "Control Type: " + bn.Current.ControlType + " " + "Automation ID: " + bn.Current.AutomationId + " " + "Item Type: " + bn.Current.ItemType + " " + "Name: " + bn.Current.Name + Environment.NewLine);
                                System.Windows.Automation.AutomationElementCollection l = bn.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                                foreach (System.Windows.Automation.AutomationElement zn in l)
                                {
                                    //   Console.Write("2nd Child: " + "Class Name: " + zn.Current.ClassName + "Control Type: " +  zn.Current.ControlType + " Automation ID " + zn.Current.AutomationId + "Item type " + zn.Current.ItemType + " Name " + zn.Current.Name + Environment.NewLine);
                                    if (zn.Current.Name.Equals("Notification bar"))
                                    {
                                        System.Windows.Automation.AutomationElementCollection lg = zn.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                                        foreach (System.Windows.Automation.AutomationElement xx in lg)
                                        {
                                            // Console.Write("3rd Child: " + "Class Name: " + xx.Current.ClassName + "Control Type: " + xx.Current.ControlType + " Automation ID " + xx.Current.AutomationId + "Item type " + xx.Current.ItemType + " Name " + xx.Current.Name + Environment.NewLine);
                                            if (xx.Current.Name.Equals(name))
                                            {
                                                System.Windows.Automation.AutomationPattern[] pats = xx.GetSupportedPatterns();
                                                foreach (System.Windows.Automation.AutomationPattern pat in pats)
                                                {
                                                    // Console.Write("Pattern ID: " + pat.Id + "Name:" + pat.ProgrammaticName);
                                                    // '10000' button click event id
                                                    if (pat.Id == 10000)
                                                    {
                                                        System.Windows.Automation.InvokePattern click = (System.Windows.Automation.InvokePattern)xx.GetCurrentPattern(pat);
                                                        click.Invoke();
                                                    }
                                                }
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Method to handle the IE9 File Download Notification Bar
        /// Uses UI Automation
        /// May want to add this as a dialog handler inheriting BaseDialogHandler
        /// </summary>
        /// <param name="name"></param>
        public void IE9FileDownload(string name)
        {
            UIAutomationClass uac = new UIAutomationClass();
            System.Windows.Automation.AutomationElementCollection test = uac.GetDeskTopChildren();
            foreach (System.Windows.Automation.AutomationElement x in test)
            {
                if (x.Current.ClassName.Equals("IEFrame"))
                {
                    // Console.Write(x.Current.ClassName + " " + x.Current.ControlType + " " + x.Current.AutomationId + " " + x.Current.ItemType + " " + x.Current.Name + Environment.NewLine);
                    System.Windows.Automation.AutomationElementCollection y = x.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                    foreach (System.Windows.Automation.AutomationElement z in y)
                    {
                        // Console.Write(x.Current.ClassName + " " + z.Current.ClassName + " " + z.Current.ControlType + " " + z.Current.AutomationId + " " + z.Current.ItemType + " " + z.Current.Name + Environment.NewLine);
                        if (z.Current.ClassName.Equals("Frame Notification Bar"))
                        {
                            System.Windows.Automation.AutomationElementCollection g = x.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                            foreach (System.Windows.Automation.AutomationElement bn in g)
                            {
                                // Console.Write("First Child" + "Class Name: " + bn.Current.ClassName + " " + "Control Type: " + bn.Current.ControlType + " " + "Automation ID: " + bn.Current.AutomationId + " " + "Item Type: " + bn.Current.ItemType + " " + "Name: " + bn.Current.Name + Environment.NewLine);
                                System.Windows.Automation.AutomationElementCollection l = bn.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                                foreach (System.Windows.Automation.AutomationElement zn in l)
                                {
                                    //   Console.Write("2nd Child: " + "Class Name: " + zn.Current.ClassName + "Control Type: " +  zn.Current.ControlType + " Automation ID " + zn.Current.AutomationId + "Item type " + zn.Current.ItemType + " Name " + zn.Current.Name + Environment.NewLine);
                                    if (zn.Current.Name.Equals("Notification bar"))
                                    {
                                        System.Windows.Automation.AutomationElementCollection lg = zn.FindAll(System.Windows.Automation.TreeScope.Children, System.Windows.Automation.Condition.TrueCondition);
                                        foreach (System.Windows.Automation.AutomationElement xx in lg)
                                        {
                                            // Console.Write("3rd Child: " + "Class Name: " + xx.Current.ClassName + "Control Type: " + xx.Current.ControlType + " Automation ID " + xx.Current.AutomationId + "Item type " + xx.Current.ItemType + " Name " + xx.Current.Name + Environment.NewLine);
                                            if (xx.Current.Name.Equals(name))
                                            {
                                                System.Windows.Automation.AutomationPattern[] pats = xx.GetSupportedPatterns();
                                                foreach (System.Windows.Automation.AutomationPattern pat in pats)
                                                {
                                                    // Console.Write("Pattern ID: " + pat.Id + "Name:" + pat.ProgrammaticName);
                                                    // '10000' button click event id 
                                                    if (pat.Id == 10000)
                                                    {
                                                        System.Windows.Automation.InvokePattern click = (System.Windows.Automation.InvokePattern)xx.GetCurrentPattern(pat);
                                                        click.Invoke();
                                                    }
                                                }
                                                return;
                                            }
                                        }
                                    }

                                }
                            }
                        }
                    }
                }
            }

        }