Ejemplo n.º 1
0
        public static string Description(this Condition condition)
        {
            switch (condition)
            {
            case PropertyCondition propertyCondition:
            {
                if (Equals(propertyCondition.Property, AutomationElementIdentifiers.ControlTypeProperty))
                {
                    // ReSharper disable once PossibleNullReferenceException
                    return($"ControlType == {ControlType.LookupById((int)propertyCondition.Value).ProgrammaticName.TrimStart("ControlType.")}");
                }

                return($"{propertyCondition.Property.ProgrammaticName.TrimStart("AutomationElementIdentifiers.").TrimEnd("Property")} == {propertyCondition.Value}");
            }

            case AndCondition andCondition:
                return($"({string.Join(" && ", andCondition.GetConditions().Select(x => x.Description()))})");

            case OrCondition orCondition:
                return($"({string.Join(" || ", orCondition.GetConditions().Select(x => x.Description()))})");

            case NotCondition notCondition:
                return($"!{notCondition.Condition.Description()}");

            case var c when c == Condition.TrueCondition:
                return("Condition.TrueCondition");

            case var c when c == Condition.FalseCondition:
                return("Condition.FalseCondition");

            default:
                return(condition.ToString());
            }
        }
Ejemplo n.º 2
0
 public static void EnterNumber(string number)
 {
     while (true)
     {
         try
         {
             InvokePattern currentPattern = number_edit.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
             currentPattern.Invoke();
             SendCtrlhotKey('A');
             Clipboard.SetText(number);
             currentPattern.Invoke();
             SendCtrlhotKey('V');
             Thread.Sleep(100);
             return;
         }
         catch
         {
             SendMessage(FindWindow("Qt5QWindowIcon", "Viber"), WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
             AutomationElement element = AutomationElement.FromHandle(FindWindow("Qt5QWindowOwnDCIcon", null));
             ControlType       byId    = ControlType.LookupById(0xc354);
             number_edit = element.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, byId));
             SendCtrlhotKey('D');
         }
     }
 }
Ejemplo n.º 3
0
        public static bool StartWork()
        {
            if (button == null)
            {
                button = AutomationElement.FromHandle(FindWindow("Qt5QWindowOwnDCIcon", null)).FindAll(TreeScope.Children, Condition.TrueCondition)[6];
            }
            if (number_edit == null)
            {
                AutomationElement element2 = AutomationElement.FromHandle(FindWindow("Qt5QWindowOwnDCIcon", null));
                ControlType       byId     = ControlType.LookupById(0xc354);
                number_edit = element2.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, byId));
            }
            SendMessage(FindWindow("Qt5QWindowIcon", "Viber"), WM_CLOSE, IntPtr.Zero, IntPtr.Zero);

            hwnd = IntPtr.Zero;
            hwnd = FindWindow("Qt5QWindowOwnDCIcon", null);
            while (hwnd == IntPtr.Zero)
            {
                hwnd = FindWindow("Qt5QWindowOwnDCIcon", null);
            }
            Thread.Sleep(500);
            int           capacity = GetWindowTextLength(hwnd) + 1;
            StringBuilder lpString = new StringBuilder(capacity);

            GetWindowText(hwnd, lpString, lpString.Capacity);
            string str = lpString.ToString();

            if (lpString.ToString() == "Viber")
            {
                return(false);
            }
            SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 800, 600, 0x40);
            return(true);
        }
Ejemplo n.º 4
0
 private static object ConvertToControlType(object value)
 {
     if (value is ControlType)
     {
         return(value);
     }
     return(ControlType.LookupById((int)value));
 }
Ejemplo n.º 5
0
 private static object ConvertToControlType(object value)
 {
     // This currently passes through as-is for proxies - but need to
     // convert to ID so that UiaCore can serialize properly.
     if (value is ControlType)
     {
         return(value);
     }
     return(ControlType.LookupById((int)value));
 }
Ejemplo n.º 6
0
        private ControlType GetControlTypes(String controlTypeString)
        {
            ControlType.Button.ToString();
            AutomationControlType typeEnum;
            bool result = Enum.TryParse(controlTypeString, true, out typeEnum);

            if (result)
            {
                typeEnum = (AutomationControlType)Enum.Parse(typeof(AutomationControlType), controlTypeString);
            }
            int enumId = (int)typeEnum + 50000;

            return(ControlType.LookupById(enumId));
        }
Ejemplo n.º 7
0
        public virtual object GetDeserializedObject(object obj, Type targetType)
        {
            if (obj.GetType() == typeof(ControlTypeSurrogate))
            {
                return(ControlType.LookupById(((ControlTypeSurrogate)obj).ControlTypeId));
            }

            if (obj.GetType() == typeof(AutomationPropertySurrogate))
            {
                return(AutomationProperty.LookupById(((AutomationPropertySurrogate)obj).AutomationId));
            }

            return(obj);
        }
Ejemplo n.º 8
0
 internal static ControlType ConvertToControlType(int id)
 {
     return(ControlType.LookupById(id));
 }
Ejemplo n.º 9
0
        public virtual object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context)
        {
            int lookupId = int.Parse(xml.InnerText);

            return(ControlType.LookupById(lookupId));
        }
Ejemplo n.º 10
0
        public static AutomationElement GetAutoElemFromXML(XmlDocument XML)
        {
            AutomationElement _ReturnElement = AutomationElement.RootElement;
            //As programmed, each XMLDoc contains multiple nodes with attributes
            //containing the element specific details.

            //Lets start with getting all the nodes.
            XmlNode xmlChildNode = XML.ChildNodes[0];

            while (xmlChildNode != null)
            {
                XmlAttributeCollection NodeAttrs = xmlChildNode.Attributes;
                try
                {
                    AndCondition AllConditions = new AndCondition(new PropertyCondition(AutomationElement.NameProperty, NodeAttrs["Name"].Value),
                                                                  new PropertyCondition(AutomationElement.AutomationIdProperty, NodeAttrs["AutoID"].Value),
                                                                  new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.LookupById(int.Parse(NodeAttrs["CtrlID"].Value))),
                                                                  new PropertyCondition(AutomationElement.ClassNameProperty, NodeAttrs["Class"].Value));

                    AutomationElement _FoundElem = _ReturnElement.FindFirst(TreeScope.Descendants, AllConditions);
                    _ReturnElement = _FoundElem;
                    try { xmlChildNode = xmlChildNode.ChildNodes[0]; } catch { xmlChildNode = null; }
                }

                catch
                {
                    MessageBox.Show("Probably invalid XML format. Check that all attributes exist.", "NullReferenceException");
                    _ReturnElement = null;
                    break;
                }
            }
            return(_ReturnElement);
        }
Ejemplo n.º 11
0
        protected virtual object GetProviderPropertyValue(int propertyId)
        {
            if (propertyId == AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ExpandCollapsePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsGridPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(GridPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsLegacyIAccessiblePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(LegacyIAccessiblePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsInvokePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(InvokePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsMultipleViewPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(MultipleViewPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsRangeValuePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(RangeValuePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsScrollItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ScrollItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsScrollPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ScrollPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsSelectionItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(SelectionItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsSelectionPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(SelectionPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTablePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TablePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTextPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TextPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTogglePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TogglePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTransformPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TransformPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsValuePatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(ValuePatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsWindowPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(WindowPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsDockPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(DockPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsGridItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(GridItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.IsTableItemPatternAvailableProperty.Id)
            {
                return(IsBehaviorEnabled(TableItemPatternIdentifiers.Pattern));
            }
            else if (propertyId == AutomationElementIdentifiers.AutomationIdProperty.Id)
            {
                string name = (Component as SWF.Control)?.Name;
                if (String.IsNullOrEmpty(name))
                {
                    return(runtimeId.ToString());
                }
                else
                {
                    return(name);
                }
            }
            else if (propertyId == AutomationElementIdentifiers.IsControlElementProperty.Id)
            {
                return(true);
            }
            else if (propertyId == AutomationElementIdentifiers.IsContentElementProperty.Id)
            {
                return(true);
            }
            else if (propertyId == AutomationElementIdentifiers.IsPasswordProperty.Id)
            {
                return(false);
            }
            else if (propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id)
            {
                object controlTypeIdObj =
                    GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id);
                if (controlTypeIdObj != null)
                {
                    int controlTypeId = (int)controlTypeIdObj;
                    //On Win7, for DataGrid, DataItem and List, the ControlType.LocalizedControlType
                    //is inconsistent with the element's LocalizedControlType property.
                    if (controlTypeId == ControlType.DataGrid.Id)
                    {
                        return(Catalog.GetString("data grid"));
                    }
                    else if (controlTypeId == ControlType.DataItem.Id)
                    {
                        return(Catalog.GetString("data item"));
                    }
                    else if (controlTypeId == ControlType.List.Id)
                    {
                        return(Catalog.GetString("list"));
                    }
                    else
                    {
                        var ct = ControlType.LookupById(controlTypeId);
                        return(ct != null ? ct.LocalizedControlType : null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
            {
                Rect bounds = (Rect)
                              GetPropertyValue(AEIds.BoundingRectangleProperty.Id);
                if (Control == null)
                {
                    return(Helper.IsOffScreen(Helper.RectToRectangle(bounds)));
                }
                return(Helper.IsOffScreen(bounds, Control));
            }
            else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
            {
                return(BoundingRectangleProperty);
            }

            //Control-like properties
            if (Control == null)
            {
                return(null);
            }
            else if (propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id)
            {
                return(Control.Enabled);
            }
            else if (propertyId == AutomationElementIdentifiers.NameProperty.Id)
            {
                if (!string.IsNullOrEmpty(Control.AccessibleName))
                {
                    return(Control.AccessibleName);
                }

                IRawElementProviderSimple label =
                    GetPropertyValue(AutomationElementIdentifiers.LabeledByProperty.Id)
                    as IRawElementProviderSimple;
                if (label == null)
                {
                    int controlType = (int)GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id);
                    // http://msdn.microsoft.com/en-us/library/ms748367.aspx
                    // "The Name property should never contain the textual contents of the edit control."
                    if (controlType == ControlType.Edit.Id || controlType == ControlType.Document.Id)
                    {
                        return(string.Empty);
                    }
                    else
                    {
                        return(Helper.StripAmpersands(Control.Text));
                    }
                }
                else
                {
                    return(label.GetPropertyValue(AutomationElementIdentifiers.NameProperty.Id));
                }
            }
            else if (propertyId == AutomationElementIdentifiers.LabeledByProperty.Id)
            {
                IRawElementProviderFragment thisAsFragment = this as IRawElementProviderFragment;
                if (thisAsFragment == null)
                {
                    return(null);
                }

                IRawElementProviderFragment parent = thisAsFragment.Navigate(NavigateDirection.Parent);
                if (parent == null || parent == thisAsFragment)
                {
                    return(null);
                }

                IRawElementProviderFragment closestLabel = null;
                double closestLabelDistance = double.MaxValue;

                parent.NavigateEachChildProvider((IRawElementProviderFragment sibling) => {
                    if (sibling == this)
                    {
                        return;
                    }
                    if ((int)sibling.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id) == ControlType.Text.Id)
                    {
                        double siblingDistance;
                        if ((siblingDistance = DistanceFrom(sibling)) < closestLabelDistance)
                        {
                            closestLabel         = sibling;
                            closestLabelDistance = siblingDistance;
                        }
                    }
                });

                return(closestLabel);
            }
            else if (propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id)
            {
                return(Control.CanFocus && Control.CanSelect);
            }
            else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
            {
                return(Control.Focused);
            }
            else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id)
            {
                return(Helper.GetClickablePoint(this));
            }
            else if (propertyId == AEIds.FrameworkIdProperty.Id)
            {
                return("WinForm");                // TODO: Localizable?
            }
            else if (propertyId == AutomationElementIdentifiers.HelpTextProperty.Id)
            {
                if (ToolTip == null)
                {
                    return(Control.AccessibleDescription ?? string.Empty);
                }
                else
                {
                    return(ToolTip.GetToolTip(Control));
                }
            }
            else if (propertyId == AutomationElementIdentifiers.AccessKeyProperty.Id)
            {
                if (!Control.Text.Contains("&"))
                {
                    return(null);
                }
                else
                {
                    int index = Control.Text.LastIndexOf('&') + 1;
                    return("Alt+" + Control.Text.Substring(index, 1));
                }
            }
            else if (propertyId == AEIds.ProcessIdProperty.Id)
            {
                // TODO: Write test for this property
                if (!pid.HasValue)
                {
                    pid = System.Diagnostics.Process.GetCurrentProcess().Id;
                }
                return(pid.Value);
            }
            else if (propertyId == AutomationElementIdentifiers.NativeWindowHandleProperty.Id)
            {
                return(Control.Handle);                // TODO: Should be int, maybe?
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// A method to fetch the song that's currently playing on Youtube.
        /// returns empty string if unsuccessful and custom pause text is not set.
        /// Currently supported browsers: Google Chrome
        /// </summary>
        /// <param name="website"></param>
        /// <returns>Returns String with Youtube Video Title</returns>
        public string FetchBrowser(string website)
        {
            string browser = "";

            // chrome, opera, msedge
            foreach (string s in browsers)
            {
                if (Process.GetProcessesByName(s).Length > 0)
                {
                    browser = s;
                    break;
                }
            }

            Process[] procsBrowser = Process.GetProcessesByName(browser);

            foreach (Process procBrowser in procsBrowser)
            {
                // the chrome process must have a window
                if (procBrowser.MainWindowHandle == IntPtr.Zero)
                {
                    continue;
                }

                AutomationElement elm = _parent == null?AutomationElement.FromHandle(procBrowser.MainWindowHandle) : _parent;

                if (_id == 0)
                {
                    // find the automation element
                    try
                    {
                        AutomationElementCollection elementCollection = elm.FindAll(TreeScope.Descendants,
                                                                                    new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem));
                        foreach (AutomationElement elem in elementCollection)
                        {
                            // if the Tabitem Name contains Youtube
                            switch (website)
                            {
                            case "YouTube":
                                if (elem.Current.Name.Contains("YouTube"))
                                {
                                    _id     = elem.Current.ControlType.Id;
                                    _parent = TreeWalker.RawViewWalker.GetParent(elem);
                                    // Regex pattern to replace the notification in front of the tab (1) - (99+)
                                    return(FormattedString("YouTube", Regex.Replace(elem.Current.Name, @"^\([\d]*(\d+)[\d]*\+*\)", "")));
                                }
                                break;

                            case "Deezer":
                                if (elem.Current.Name.Contains("Deezer"))
                                {
                                    _id     = elem.Current.ControlType.Id;
                                    _parent = TreeWalker.RawViewWalker.GetParent(elem);
                                    return(FormattedString("Deezer", elem.Current.Name));
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogExc(ex);
                        // Chrome has probably changed something, and above walking needs to be modified. :(
                        // put an assertion here or something to make sure you don't miss it
                    }
                }
                else
                {
                    try
                    {
                        AutomationElement element =
                            elm.FindFirst(TreeScope.Descendants,
                                          new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.LookupById(_id)));

                        // if the Tabitem Name contains Youtube
                        switch (website)
                        {
                        case "YouTube":
                            if (element == null)
                            {
                                break;
                            }
                            if (element.Current.Name.Contains("YouTube"))
                            {
                                _id     = element.Current.ControlType.Id;
                                _parent = TreeWalker.RawViewWalker.GetParent(element);
                                // Regex pattern to replace the notification in front of the tab (1) - (99+)
                                return(FormattedString("YouTube", Regex.Replace(element.Current.Name, @"^\([\d]*(\d+)[\d]*\+*\)", "")));
                            }
                            break;

                        case "Deezer":
                            if (element.Current.Name.Contains("Deezer"))
                            {
                                _id     = element.Current.ControlType.Id;
                                _parent = TreeWalker.RawViewWalker.GetParent(element);
                                return(FormattedString("Deezer", element.Current.Name));
                            }
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }
            return("");
        }
Ejemplo n.º 13
0
        public static AutomationElement GetAutoElemFromXML(XmlDocument XML)
        {
            AutomationElement _ReturnElement = AutomationElement.RootElement;
            //As programmed, each XMLDoc contains multiple nodes with attributes
            //containing the element specific details.

            //Lets start with getting all the nodes.
            XmlNodeList xmlNodeList = XML.ChildNodes;

            int runIdx = 0;

            foreach (XmlNode xmlNode in xmlNodeList)
            {
                XmlAttributeCollection NodeAttrs = xmlNode.Attributes;


                AndCondition AllConditions = new AndCondition(new PropertyCondition(AutomationElement.NameProperty, NodeAttrs["Name"].Value),
                                                              new PropertyCondition(AutomationElement.AutomationIdProperty, NodeAttrs["AutoID"].Value),
                                                              new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.LookupById(int.Parse(NodeAttrs["CtrlID"].Value))),
                                                              new PropertyCondition(AutomationElement.ClassNameProperty, NodeAttrs["Class"].Value));
                _ReturnElement = _ReturnElement.FindFirst(TreeScope.Children, AllConditions);
                runIdx++;
            }

            return(_ReturnElement);
        }