Пример #1
0
        private static void DownLoadFile(string strWindowTitle)
        {
            IntPtr TargetHandle = FindWindowByCaption(IntPtr.Zero, strWindowTitle);
            AutomationElementCollection ParentElements = AutomationElement.FromHandle(TargetHandle).FindAll(TreeScope.Children, Condition.TrueCondition);

            foreach (AutomationElement ParentElement in ParentElements)
            {
                // Identidfy Download Manager Window in Internet Explorer
                if (ParentElement.Current.ClassName == "Frame Notification Bar")
                {
                    AutomationElementCollection ChildElements = ParentElement.FindAll(TreeScope.Children, Condition.TrueCondition);
                    // Idenfify child window with the name Notification Bar or class name as DirectUIHWND
                    foreach (AutomationElement ChildElement in ChildElements)
                    {
                        if (ChildElement.Current.Name == "Notification bar" || ChildElement.Current.ClassName == "DirectUIHWND")
                        {
                            AutomationElementCollection DownloadCtrls = ChildElement.FindAll(TreeScope.Children, Condition.TrueCondition);
                            foreach (AutomationElement ctrlButton in DownloadCtrls)
                            {
                                //Now invoke the button click whichever you wish
                                if (ctrlButton.Current.Name.ToLower() == "save")
                                {
                                    var invokePattern = ctrlButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                                    invokePattern.Invoke();
                                }
                            }
                        }
                    }
                }
            }
        }
        public void DownLoadFile(string path = "")
        {
            AutomationElementCollection ParentElements = AutomationElement.FromHandle(Ie.hWnd).FindAll(TreeScope.Children, Condition.TrueCondition);

            foreach (AutomationElement ParentElement in ParentElements)
            {
                // Identidfy Download Manager Window in Internet Explorer
                if (ParentElement.Current.ClassName == "Frame Notification Bar")
                {
                    AutomationElementCollection ChildElements = ParentElement.FindAll(TreeScope.Children, Condition.TrueCondition);
                    // Idenfify child window with the name Notification Bar or class name as DirectUIHWND
                    foreach (AutomationElement ChildElement in ChildElements)
                    {
                        if (ChildElement.Current.Name == "Notification bar" || ChildElement.Current.ClassName == "DirectUIHWND")
                        {
                            AutomationElementCollection DownloadCtrls = ChildElement.FindAll(TreeScope.Children, Condition.TrueCondition);
                            foreach (AutomationElement ctrlButton in DownloadCtrls)
                            {
                                //Now we try to find save button
                                if (ctrlButton.Current.Name.ToLower() == "save")
                                {
                                    //after that we need to click the arrow to expand hidden options
                                    var subButton       = ctrlButton.FindAll(TreeScope.Subtree, Condition.TrueCondition);
                                    var invokeSubButton = subButton[1].GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                                    invokeSubButton.Invoke();
                                    G1ANT.Language.KeyboardTyper.Type("⋘down⋙⋘enter⋙", string.Empty, null, IntPtr.Zero, 400, false, 20, false);
                                    Thread.Sleep(1000);
                                    Language.KeyboardTyper.Type(path, string.Empty, null, IntPtr.Zero, 400, false, 20, false);
                                    Language.KeyboardTyper.Type("⋘enter⋙", string.Empty, null, IntPtr.Zero, 400, false, 20, false);
                                }
                            }
                        }
                    }
                }
            }
        }