With White and without white

Sep 10, 2009 at 2:26 PM
Edited Sep 10, 2009 at 2:27 PM

Hi,

I've got two pieces of code. The one with white is not working.

With white:

        void DoTheTrick()
        {
            Core.Application Remedy = Core.Application.AttachOrLaunch(new System.Diagnostics.ProcessStartInfo("aruser.exe"));
            Window window = Remedy.GetWindow("Remedy User");

            Core.UIItems.ListBoxItems.ListBox listBox = window.Get<Core.UIItems.ListBoxItems.ListBox>("");

            if (listBox != null)
            {
                listBox.Items[0].Select();
            }
        }

 

Without white:

            AutomationElement ae = AutomationElement.FromHandle(r.MainWindowHandle); //r == mainprocess (aruser.exe)

            PropertyCondition cond1 = new PropertyCondition(AutomationElement.NameProperty, "ASTRID: Melding nieuw BSD LE");
            PropertyCondition cond2 = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem);
            AndCondition andcondition1 = new AndCondition(cond1, cond2);
            AutomationElement macro = ae.FindFirst(TreeScope.Descendants, andcondition1);
            if (macro != null)
            {
                object patternObject;
                macro.TryGetCurrentPattern(SelectionItemPattern.Pattern, out patternObject);
                SelectionItemPattern pattern = patternObject as SelectionItemPattern;
                if (pattern != null)
                {
                    pattern.Select();
                }
            }

Where could be the problem? The control listBox is not null, so it is selected.

Regards,

Roel

 

Coordinator
Sep 20, 2009 at 6:30 AM

in the first one you are looking for listbox whose automationid is empty. in the second one you are providing more criterias.

I think you should use the method which takes searchcriteria. Search criteria can be created off name, etc.

Sep 21, 2009 at 8:32 AM

Hi,

Thanks for your reply!

Now I've got the following code and the listItem is not empty (null) anymore. The problem is that the AutomationID is still empty. When I take a look at the UISpy interface of this listitem, the AutomationID is also empty.

        void DoTheTrick()
        {
            Core.Application Remedy = Core.Application.AttachOrLaunch(new System.Diagnostics.ProcessStartInfo("aruser.exe"));
            Window window = Remedy.GetWindow("Remedy User");

            ListItem listItem = (ListItem)window.Get(SearchCriteria.ByControlType(ControlType.ListItem).AndByText("ASTRID: Melding nieuw BSD LE"));

            if (listItem != null)
            {
                MessageBox.Show(listItem.Id);
                listItem.Select();
            }
        }

Is the AutomationID a required criteria for White?

Thanks!

Roel

 

Sep 27, 2009 at 8:19 PM

No it is one criteria but not needed, you can also search by Name or only ControlType. 

But you can use more criterias to be sure you get the correct element.