public void ShouldDescribeNegatedCompoundsUsingNot()
        {
            var nameCondition = new PropertyCondition(AutomationElement.NameProperty, "Wooble");
            const string expected = "not Name='Wooble'";

            Assert.AreEqual(expected, new ConditionDescriber().Describe(new NotCondition(nameCondition)));
        }
Esempio n. 2
0
        private static bool ButtonClick(AutomationElement inElement, string automationId)
        {
            PropertyCondition btnCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId);

            Console.WriteLine("Searching for the {0} button...", automationId);
            AutomationElement control = inElement.FindFirst(TreeScope.Descendants, btnCondition);
            if (control != null)
            {
                Console.WriteLine("Clicking the {0} button", automationId);

                object controlType = control.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty);
                if (controlType == ControlType.Button)
                {
                    InvokePattern clickCommand = control.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                    clickCommand.Invoke();
                }
                else if (controlType == ControlType.RadioButton)
                {
                    SelectionItemPattern radioCheck = control.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern;
                    radioCheck.Select();
                }
                System.Threading.Thread.Sleep(2000);
                Console.WriteLine("Button {0} clicked.", automationId);

                return true;
            }
            else
            {
                Console.WriteLine("Could not find button {0} ", automationId);
                return false;
            }
        }
Esempio n. 3
0
        public override void DoExecute()
        {
            AutomationElement a = UiElement.AutomationElement;

            Console.WriteLine(a.Current.AutomationId);

            ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

            expandCollapsePattern.Expand();
            var comboBoxEditItemCondition = new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "ComboBoxEditItem");
            var listItems = a.FindAll(TreeScope.Subtree, comboBoxEditItemCondition);//It can only get one item in the list (the first one).
            var testItem  = listItems[listItems.Count - 1];
            int index1    = 0;
            int index     = 0;

            foreach (AutomationElement item in listItems)
            {
                foreach (AutomationElement itemChild in item.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock")))
                {
                    if (itemChild.Current.Name == Control.text)
                    {
                        //testItem=
                    }
                }


                index++;
            }

            (testItem.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern).Select();
            expandCollapsePattern.Collapse();
        }
        public void ShouldDescribeAPropertyConditionWithConditionAndValue()
        {
            var condition = new PropertyCondition(AutomationElement.NameProperty, "Wibble");
            const string expected = "Name='Wibble'";

            Assert.AreEqual(expected, new ConditionDescriber().Describe(condition));
        }
Esempio n. 5
0
        public void GetControls()
        {
            //window = AutomationElement.FromHandle(new IntPtr(window.Current.NativeWindowHandle));
            var autoIds = new string[] {
                "12005",
                "12006",
                "12007",
                "2010"};
            var types = new TradeContorlTypes[] {
                TradeContorlTypes.BuyCode,
                TradeContorlTypes.BuyMoney,
                TradeContorlTypes.BuyAmount,
                TradeContorlTypes.BuyButton };

            PropertyCondition propertyCondition = null;
            for (var i = 0; i < autoIds.Length; i++)
            {
                propertyCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, autoIds[i]);
                var control = window.FindFirst(TreeScope.Subtree, propertyCondition);
                if (control != null)
                {
                    TradeControls.Instance().AddControl(types[i], control);
                }
            }
        }
Esempio n. 6
0
        public void ControlViewConditionTest()
        {
            SWA.Condition controlViewCond = SWA.Automation.ControlViewCondition;
            Assert.IsNotNull(controlViewCond, "ControlViewCondition");

            SWA.PropertyCondition controlViewPropCond = controlViewCond as SWA.PropertyCondition;
            Assert.IsNull(controlViewPropCond, "ControlViewCondition is not a PropertyCondition");

            SWA.AndCondition controlViewAndCond = controlViewCond as SWA.AndCondition;
            Assert.IsNull(controlViewAndCond, "ControlViewCondition is not a AndCondition");

            SWA.OrCondition controlViewOrCond = controlViewCond as SWA.OrCondition;
            Assert.IsNull(controlViewOrCond, "ControlViewCondition is not a OrCondition");

            SWA.NotCondition controlViewNotCond = controlViewCond as SWA.NotCondition;
            Assert.IsNotNull(controlViewNotCond, "ControlViewCondition is a NotCondition");

            SWA.Condition subCond = controlViewNotCond.Condition;
            Assert.IsNotNull(subCond, "ControlViewCondition.Condition");

            SWA.PropertyCondition subPropertyCond = subCond as SWA.PropertyCondition;
            Assert.IsNotNull(subPropertyCond, "ControlViewCondition.Condition is a PropertyCondition");
            Assert.AreEqual(AEIds.IsControlElementProperty,
                            subPropertyCond.Property,
                            "ControlViewCondition.Condition.Property");
            Assert.AreEqual(false,
                            subPropertyCond.Value,
                            "ControlViewCondition.Condition.Value");
            Assert.AreEqual(SWA.PropertyConditionFlags.None,
                            subPropertyCond.Flags,
                            "ControlViewCondition.Condition.Flags");
        }
        public static void getScreenshotForWindowwithTitle(string partorfulltext, string screenshotlocation)
        {
            AutomationElement root = AutomationElement.RootElement;
            Condition cndwindows = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
            AutomationElementCollection ActiveWindows = root.FindAll(TreeScope.Descendants, cndwindows);

            AutomationElement ActiveWindow = null;
            foreach (AutomationElement windw in ActiveWindows)
            {
                if (windw.Current.Name.Contains(partorfulltext))
                {
                    ActiveWindow = windw;
                    break;
                }
            }
            ActiveWindow.SetFocus();
            WindowPattern wndptn = (WindowPattern)ActiveWindow.GetCurrentPattern(WindowPattern.Pattern);
            wndptn.SetWindowVisualState(WindowVisualState.Maximized);
            System.Threading.Thread.Sleep(2000);
            Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                    Screen.PrimaryScreen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bitmap as Image);
            graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
            bitmap.Save(  Path.Combine(screenshotlocation, Guid.NewGuid() + ".jpg"), ImageFormat.Jpeg);
        }
Esempio n. 8
0
        /// <summary>
        /// Find application from desktop
        /// </summary>
        /// <param name="appPath"></param>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public static AutomationElement FindApplicationByTitle(string titile)
        {
            Helper.ValidateArgumentNotNull(titile, "Title");

            var desktop = AutomationElement.RootElement;
            Condition condition = new PropertyCondition(AutomationElement.NameProperty, titile);
            return desktop.FindFirst(TreeScope.Descendants,condition);
        }
Esempio n. 9
0
        public static string GetNamePropertyOf(this AutomationElement dialogWindow, string type)
        {
            if (dialogWindow == null) throw new ArgumentNullException("dialogWindow");

            var controlTypePropertyCondition = new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, type);
            var firstResultOfCondition = dialogWindow.FindFirst(TreeScope.Children, controlTypePropertyCondition);
            return firstResultOfCondition.GetCurrentPropertyValue(AutomationElement.NameProperty) as string;
        }
 public void ConditionSetByConstructor()
 {
     var automationProperty = AutomationElement.NameProperty;
      var valueProvider = CreateValueProvider(automationProperty);
      var condition = new PropertyCondition(automationProperty, "");
      var def = CreateElementDefinition(TreeScope.Descendants, automationProperty, valueProvider, condition);
      Assert.IsTrue(ReferenceEquals(condition, def.Condition));
 }
Esempio n. 11
0
        /// <summary>
        /// Finds a descendent of the focused element that has the specified
        /// className, controlType and automationID
        /// </summary>
        /// <param name="focusedElement"></param>
        /// <param name="className">class name </param>
        /// <param name="controlType">controlType</param>
        /// <param name="automationId">automation id </param>
        /// <returns>automation element if found null otherwise</returns>
        public static AutomationElement FindElementByAutomationId(AutomationElement focusedElement, String className, object controlType, String automationId)
        {
            var controlTypeProperty = new PropertyCondition(AutomationElement.ControlTypeProperty, controlType);
            var automationIdProperty = new PropertyCondition(AutomationElement.AutomationIdProperty, automationId);
            var classNameProperty = new PropertyCondition(AutomationElement.ClassNameProperty, className);
            var findControl = new AndCondition(controlTypeProperty, automationIdProperty, classNameProperty);

            var retVal = focusedElement.FindFirst(TreeScope.Descendants, findControl);
            return retVal;
        }
Esempio n. 12
0
        public static AutomationElementCollection FindElementByClassName(AutomationElement parentElement, string className, ControlType type)
        {
            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            PropertyCondition IDCondition = new PropertyCondition(AutomationElement.ClassNameProperty, className);

            AndCondition andCondition = new AndCondition(typeCondition, IDCondition);

            return parentElement.FindAll(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
Esempio n. 13
0
        public static AutomationElement FindElementById(AutomationElement parentElement, string automationID, ControlType type)
        {
            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            PropertyCondition IDCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID);

            AndCondition andCondition = new AndCondition(typeCondition, IDCondition);

            return parentElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
Esempio n. 14
0
        public static AutomationElement FindWindowByName(AutomationElement rootElement, string name, ControlType type)
        {
            PropertyCondition nameCondition = new PropertyCondition(AutomationElement.NameProperty, name);

            PropertyCondition typeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, type);

            AndCondition andCondition = new AndCondition(nameCondition, typeCondition);

            return rootElement.FindFirst(TreeScope.Element | TreeScope.Descendants, andCondition);
        }
Esempio n. 15
0
		public void ConditionTest ()
		{
			AssertRaises<ArgumentNullException> (
				() => new TreeWalker (null),
				"passing null to TreeWalker constructor");

			Condition buttonCondition = new PropertyCondition (AEIds.ControlTypeProperty, ControlType.Button);
			TreeWalker buttonWalker = new TreeWalker (buttonCondition);
			Assert.AreEqual (buttonCondition, buttonWalker.Condition, "Condition");
		}
        public void ShouldDescribeCompoundConditionsUsingOr()
        {
            var nameCondition = new PropertyCondition(AutomationElement.NameProperty, "Wubble");
            var controlTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window);
            var condition = new OrCondition(nameCondition, controlTypeCondition);

            var expected = "(Name='Wubble' or ControlType='" + ControlType.Window.Id + "')";

            Assert.AreEqual(expected, new ConditionDescriber().Describe(condition));
        }
Esempio n. 17
0
		public void GetFirstChildTest ()
		{
			Condition buttonCondition = new PropertyCondition (AEIds.ControlTypeProperty, ControlType.Button);
			TreeWalker buttonWalker = new TreeWalker (buttonCondition);

			AssertRaises<ArgumentNullException> (
				() => buttonWalker.GetFirstChild (null),
				"passing null to TreeWalker.GetFirstChild");

			VerifyGetFirstChild (buttonWalker, groupBox1Element, button7Element);
		}
Esempio n. 18
0
 public void TreeFilterTest()
 {
     CacheRequest target = new CacheRequest();
     PropertyCondition expected = new PropertyCondition(AutomationElement.NameProperty, "foo");
     PropertyCondition actual;
     target.TreeFilter = expected;
     actual = (PropertyCondition)target.TreeFilter;
     Assert.AreEqual(expected.Flags, actual.Flags);
     Assert.AreEqual(expected.Property, actual.Property);
     Assert.AreEqual(expected.Value, actual.Value);
 }
 public void NativePropertyCondition()
 {
     SearchCondition test = SearchConditionFactory.CreateForNativeProperty(AutomationElement.IsControlElementProperty, true);
     PropertyCondition expected;
     expected = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
     Assert.AreEqual((bool)expected.Value,(bool)((PropertyCondition)test.AutomationCondition).Value);
     Assert.AreEqual(expected.Property.ProgrammaticName, ((PropertyCondition)test.AutomationCondition).Property.ProgrammaticName);
     expected = new PropertyCondition(AutomationElement.NameProperty, "hello");
     test = SearchConditionFactory.CreateForNativeProperty(AutomationElement.NameProperty, "hello");
     Assert.AreEqual((string)expected.Value, (string)((PropertyCondition)test.AutomationCondition).Value);
     Assert.AreEqual(expected.Property.ProgrammaticName, ((PropertyCondition)test.AutomationCondition).Property.ProgrammaticName);
 }
Esempio n. 20
0
 public int Find(int parent, int index)
 {
     AutomationElement baseElement = base.Find(parent);
     Condition locator = new PropertyCondition(AutomationElement.ControlTypeProperty, controlType);
     AutomationElementCollection elements = baseElement.FindAll(TreeScope.Subtree, locator);
     if (elements.Count <= index)
     {
         return 0;
     }
     logger.Debug(String.Format("Found hwnd: {0}",elements[index].Current.NativeWindowHandle));
     return elements[index].Current.NativeWindowHandle;
 }
Esempio n. 21
0
 private static AutomationElement TryGetWindowElement(String windowAutomationId, Int32 timeoutMs)
 {
     var desktop = AutomationElement.RootElement;
     var condition = new PropertyCondition(AutomationElement.AutomationIdProperty, windowAutomationId);
     var getWindowElementOperation = new UiOperation<AutomationElement>(
         null,
         () => desktop.FindFirst(TreeScope.Children, condition),
         e => e != null,
         timeoutMs,
         150);
     return getWindowElementOperation.Invoke();
 }
Esempio n. 22
0
        /// <summary>
        /// Extract Window from parent window
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="titleName"></param>
        /// <returns></returns>
        public static AutomationElement ExtractElement(AutomationElement parent, string nameValue, TreeScope treeScope)
        {
            ValidateArgumentNotNull(parent, "Extract Window from parent window");
            Condition condition = new PropertyCondition(AutomationElement.NameProperty, nameValue);
            AutomationElement appElement;
            DateTime timeOut = DateTime.Now.AddMilliseconds(TimeOutMillSec);
            do
            {
                appElement = parent.FindFirst(treeScope, condition);
            } while (appElement == null && DateTime.Now < timeOut);

            return appElement;
        }
Esempio n. 23
0
 public InternalTreeWalker()
 {
     // TreeWalker instance as a global variable started consuming more
     // memory over a period of time, moving the code to individual methods
     // kept the memory usage low
     // Ignore Ldtpd from list of applications
     Condition condition1 = new PropertyCondition(AutomationElement.ProcessIdProperty,
         Process.GetCurrentProcess().Id);
     Condition condition2 = new AndCondition(new Condition[] {
         System.Windows.Automation.Automation.ControlViewCondition,
         new NotCondition(condition1)});
     walker = new TreeWalker(condition2);
 }
Esempio n. 24
0
        public void ContentViewConditionTest()
        {
            SWA.Condition contentViewCond = SWA.Automation.ContentViewCondition;
            Assert.IsNotNull(contentViewCond, "ContentViewCondition");

            SWA.PropertyCondition contentViewPropCond = contentViewCond as SWA.PropertyCondition;
            Assert.IsNull(contentViewPropCond, "ContentViewCondition is not a PropertyCondition");

            SWA.AndCondition contentViewAndCond = contentViewCond as SWA.AndCondition; Assert.IsNull(contentViewPropCond, "ContentViewCondition is not a PropertyCondition");
            Assert.IsNull(contentViewAndCond, "ContentViewCondition is not a AndCondition");

            SWA.OrCondition contentViewOrCond = contentViewCond as SWA.OrCondition;
            Assert.IsNull(contentViewOrCond, "ContentViewCondition is not a OrCondition");

            SWA.NotCondition contentViewNotCond = contentViewCond as SWA.NotCondition;
            Assert.IsNotNull(contentViewNotCond, "ContentViewCondition is a NotCondition");

            SWA.Condition subCond = contentViewNotCond.Condition;
            Assert.IsNotNull(subCond, "ContentViewCondition.Condition");

            SWA.OrCondition subOrCond = subCond as SWA.OrCondition;
            Assert.IsNotNull(subOrCond, "ContentViewCondition.Condition is a OrCondition");

            SWA.Condition [] subSubConditions = subOrCond.GetConditions();
            Assert.AreEqual(2, subSubConditions.Length, "ContentViewCondition.Condition.GetConditions length");

            SWA.PropertyCondition subSubPropertyCond1 = subSubConditions [0] as SWA.PropertyCondition;
            Assert.IsNotNull(subSubPropertyCond1);
            SWA.PropertyCondition subSubPropertyCond2 = subSubConditions [1] as SWA.PropertyCondition;
            Assert.IsNotNull(subSubPropertyCond2);

            Assert.AreEqual(AEIds.IsControlElementProperty,
                            subSubPropertyCond1.Property,
                            "subcondition1 Property");
            Assert.AreEqual(false,
                            subSubPropertyCond1.Value,
                            "subcondition1 Value");
            Assert.AreEqual(SWA.PropertyConditionFlags.None,
                            subSubPropertyCond1.Flags,
                            "subcondition1 Flags");

            Assert.AreEqual(AEIds.IsContentElementProperty.ProgrammaticName,
                            subSubPropertyCond2.Property.ProgrammaticName,
                            "subcondition2 Property");
            Assert.AreEqual(false,
                            subSubPropertyCond2.Value,
                            "subcondition2 Value");
            Assert.AreEqual(SWA.PropertyConditionFlags.None,
                            subSubPropertyCond2.Flags,
                            "subcondition2 Flags");
        }
Esempio n. 25
0
        /// <summary>
        /// Exract control from parent window by AutomationID
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="automationID"></param>
        /// <returns></returns>
        public static AutomationElement ExtractElementByAutomationID(AutomationElement parent, string automationID)
        {
            ValidateArgumentNotNull(parent, "Extract Control from parent window by Automation ID, parent");
            ValidateArgumentNotNull(parent, "Extract Control from parent window by Automation ID, automation ID");
            Condition condition = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID);
            AutomationElement appElement;
            DateTime timeOut = DateTime.Now.AddMilliseconds(TimeOutMillSec);
            do
            {
                appElement = parent.FindFirst(TreeScope.Descendants, condition);
            } while (appElement == null && DateTime.Now < timeOut);

            return appElement;
        }
Esempio n. 26
0
        public static void SetValuesOnProcessCreditCardPaymentWindow(Window paymentWin, string ccNumber, string expMonth, string expYear, string nameOnCard, string secCode, string billingAddr, string zipCode)
        {
            try
            {
                Logger.logMessage("---------------------------------------------------------------------------------");

                var paymentPanel = Actions.GetPaneByName(paymentWin, "Quickbooks Payments: Process Credit Card");

                PropertyCondition editCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit);
                AutomationElementCollection editElements = paymentPanel.AutomationElement.FindAll(TreeScope.Children, editCondition);
                int count = 0;

                foreach (AutomationElement item in editElements)
                {
                    count = count + 1;
                    TestStack.White.UIItems.TextBox t = new TestStack.White.UIItems.TextBox(item, paymentWin.ActionListener);

                    if (count == 1)
                        t.Text = ccNumber;

                    if (count == 2)
                        t.Text = expMonth;

                    if (count == 3)
                        t.Text = expYear;

                    if (count == 4)
                        t.Text = nameOnCard;

                    if (count == 5)
                        t.Text = secCode;

                    if (count == 6)
                        t.Text = billingAddr;

                    if (count == 7)
                        t.Text = zipCode;
                }

                Thread.Sleep(int.Parse(Execution_Speed));
                Logger.logMessage("---------------------------------------------------------------------------------");
            }
            catch (Exception e)
            {
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }

        }
Esempio n. 27
0
 public AutomationElement Find(int hwnd)
 {
     logger.Debug(String.Format("Find: Looking for {0} hwnd",hwnd));
     logger.Debug(String.Format("Root item handle: {0}", Root.Current.NativeWindowHandle));
     PropertyCondition condition = new PropertyCondition(AutomationElement.NativeWindowHandleProperty, hwnd);
     logger.Debug(
         String.Format(
             "Setting condition for property: {0} . Value: {1}",
             condition.Property.ProgrammaticName,
             condition.Value
         )
     );
     return Root.FindFirst(TreeScope.Subtree, condition );
         //CustomConditions.ByHandle(hwnd));
 }
Esempio n. 28
0
 private static void getOutlookWindow(ref AutomationElement mainWnd)
 {
     //Create a property condition with the element's type
     PropertyCondition typeCondition = new PropertyCondition( AutomationElement.ControlTypeProperty, ControlType.Window );
     //Create a property condition with the element's name
     PropertyCondition nameCondition = new PropertyCondition( AutomationElement.NameProperty, "Inbox - " + email + " - Outlook" );
     //Create the conjunction condition
     AndCondition andCondition = new AndCondition( typeCondition, nameCondition );
     //Ask the Desktop to find the element within its children with the given condition
     mainWnd = AutomationElement.RootElement.FindFirst( TreeScope.Children, andCondition );
     while ( mainWnd == null )
     {
         mainWnd = AutomationElement.RootElement.FindFirst( TreeScope.Children, andCondition );
     }
 }
Esempio n. 29
0
		public Window(IntPtr hWnd)
			: base(hWnd)
		{
			Angle = 0;
			Scale = 1;
			hasMenu = false;

			Contacts = new WindowContacts(this);

			automationElement = AutomationElement.FromHandle(hWnd);
			PropertyCondition condition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuBar);
			AutomationElement first = automationElement.FindFirst(TreeScope.Descendants, condition);
			if (first != null && !first.Current.Name.Equals("System Menu Bar"))
				hasMenu = true;
		}
Esempio n. 30
0
 /// <summary>
 /// This method returns an element searched by its control type from the tree.
 /// </summary>
 /// <param name="root">Root Element of the control</param>
 /// <param name="controlType">Control Type of the element</param>
 /// <returns>Automation Element of teh control</returns>
 public static AutomationElement GetElement(AutomationElement root, ControlType controlType)
 {
     if (root == null)
     {
         throw new ArgumentNullException("root");
     }
     if (controlType == null)
     {
         throw new ArgumentNullException("controlType");
     }
     else
     {
         PropertyCondition condType = new PropertyCondition(AutomationElement.ControlTypeProperty, controlType);
         return root.FindFirst(TreeScope.Descendants, condType);
     }
 }
Esempio n. 31
0
        /// <summary>
        /// This method returns an element searched by its name from the tree.
        /// </summary>
        /// <param name="root">Automation Element of the control</param>
        /// <param name="name">Name of the string</param>
        /// <param name="recursive">bool(Recursive - TRUE Or FALSE)</param>
        /// <returns>Automation Element</returns>
        public static AutomationElement GetElement(AutomationElement root, string name, bool recursive)
        {
            if (root == null)
            {
                throw new ArgumentNullException("root");
            }

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            else
            {
                PropertyCondition condName = new PropertyCondition(AutomationElement.NameProperty, name);
                return root.FindFirst(recursive ? TreeScope.Descendants : TreeScope.Children, condName);
            }
        }
Esempio n. 32
0
        public void RawViewConditionTest()
        {
            SWA.Condition rawViewCond = SWA.Automation.RawViewCondition;
            Assert.IsNotNull(rawViewCond, "RawViewCondition");

            SWA.PropertyCondition rawViewPropCond = rawViewCond as SWA.PropertyCondition;
            Assert.IsNull(rawViewPropCond, "RawViewCondition is not a PropertyCondition");

            SWA.AndCondition rawViewAndCond = rawViewCond as SWA.AndCondition;
            Assert.IsNull(rawViewAndCond, "RawViewCondition is not a AndCondition");

            SWA.OrCondition rawViewOrCond = rawViewCond as SWA.OrCondition;
            Assert.IsNull(rawViewOrCond, "RawViewCondition is not a OrCondition");

            SWA.NotCondition rawViewNotCond = rawViewCond as SWA.NotCondition;
            Assert.IsNull(rawViewNotCond, "RawViewCondition is not a NotCondition");
        }
Esempio n. 33
0
        static void Main(string[] args)
        {
            AutomationElement aeDesktop = AutomationElement.RootElement;
            AutomationElement aeTimeCard;

            do
            {
                Console.WriteLine("Looking for time card thing");

                aeTimeCard = aeDesktop.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Time Card Helper"));
                Thread.Sleep(1000);
            } while (aeTimeCard == null);

            PropertyCondition prop1 = new PropertyCondition(AutomationElement.AutomationIdProperty, "caseButton");
            AutomationElement aeButton = aeTimeCard.FindFirst(TreeScope.Descendants, prop1);

            InvokePattern btnClick = aeButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
            btnClick.Invoke();
        }
Esempio n. 34
0
        private static void Automate()
        {
            Console.WriteLine("Getting RootElement...");
            AutomationElement rootElement = AutomationElement.RootElement;

            if (rootElement != null)
            {
                Condition condition = new PropertyCondition(AutomationElement.NameProperty, windowTitle);

                Console.WriteLine("Searching for {0} Window...", windowTitle);
                AutomationElement appElement = rootElement.FindFirst(TreeScope.Children, condition);

                if (appElement != null)
                {
                    foreach (string buttonId in steps[step])
                    {
                        if (!ButtonClick(appElement, buttonId))
                        {
                            Console.WriteLine("Could not find button.");
                            return;
                        }
                    }
                    step++;
                    if (step == 8)
                    {
                        Console.WriteLine("Last step. Operation finished successfully.");
                        System.Environment.Exit(0);
                    }
                    else
                    {
                        Console.WriteLine("Moving to step {0}.", step);
                    }
                }
                else
                {
                    Console.WriteLine("Could not find the Installer Window.");
                }
            }
            else
            {
                Console.WriteLine("Could not get the RootElement.");
            }
        }
Esempio n. 35
0
 static void Main(string[] args)
 {
     foreach (var proc in Process.GetProcessesByName("chrome"))
     {
         if (proc.MainWindowHandle == IntPtr.Zero)
         {
             continue;
         }
         var element = AE.FromHandle(proc.MainWindowHandle);
         //var cond = new PC(AE.NameProperty, "アドレス検索バー"));
         var cond = new PC(AE.ControlTypeProperty, CT.Edit);
         var edit = element.FindFirst(TS.Descendants, cond);
         if (edit == null)
         {
             continue;
         }
         var pat = edit.GetCurrentPattern(VP.Pattern) as VP;
         var url = pat.Current.Value as string;
         // the url value is just surface of edit control, e.g. "http://" is hidden
         Console.WriteLine(url);
     }
 }