EzLongSearch

EzLongSearch provides an abbreviated way to do searching without having to write as much code. Be sure to check out the Samples and Usage section at the bottom

Syntax

        public static class EzLongSearch

Methods

Name Return Type Description
PerformSearch(EzElement startingElement, params EzLongSearchItem[] searches) EzElement Performs a long search. This method is used when you do not want to save a variable for each step along the way

Samples and Usage

EzLongSearch is designed to provide an abbreviated searching mechanism if you need to traverse a particularly nested hierarchy. Note that searching simply by using EzElement's find methods works just as well, but this can provide some brevity in code if desired. Please note that there is an element that you may need to use later, using EzLongSearch might not be the best choice. EzLongSearch should be used to essentially pass over elements that you only need to use as a stopping point to avoid searching for descendants (which is very inefficient). See the sample below for an example of how this can be used

        const string calculatorPath = "C:\\Windows\\System32\\calculator.exe";
        using (EzProcess process = new EzProcess(calculatorPath, "Calculator"))
        {
            process.StartProcess();

            EzElement root = new EzRoot(process).RootElement;

            //The code below will do the following.  It will start with the root element.  Then it will find the first
            //child of the root element whose AutomationId property is "TestAutomationId".  Then it will find the first
            //child of that element whose Name property is "TestName".  Then, it will find the first child of that
            //element whose AutomationId property is "MoreTestAutomationId".
            EzElement endingElement = EzLongSearch.PerformSearch(root,
                new EzLongSearchItem(PropertyType.AutomationId, TestAutomationId"),
                new EzLongSearchItem(PropertyType.Name, "TestName"),
                new EzLongSearchItem(PropertyType.AutomationId, "MoreTestAutomationId")
            );
        }

The code above will do the exact same thing as this code below. Note that the code below is simply more verbose than the code above in the sense that you have to name every variable for each step of the way. Using EzLongSearch you do not have to save variable names.

        const string calculatorPath = "C:\\Windows\\System32\\calculator.exe";
        using (EzProcess process = new EzProcess(calculatorPath, "Calculator"))
        {
            process.StartProcess();

            EzElement root = new EzRoot(process).RootElement;
            EzElement firstElement = root.FindChildByAutomationId("TestAutomationId");
            EzElement secondElement = firstElement.FindChildByName("TestName");
            EzElement endingElement = secondElement.FindChildByAutomationId(MoreTestAutomationId");
        }