public LocateAutomationElementResponse HandleLocateAutomationElementRequest( LocateAutomationElementRequest request) { Console.WriteLine("Start HandleLocateAutomationElementRequest : " + request); // Results that will be returned from method var results = new List <AutomationElementWrapper>(); // Base node var baseNode = (string.IsNullOrEmpty(request.ParrentWinDriverElementId)) ? AutomationElement.RootElement : _automationElementRepository.Get(request.ParrentWinDriverElementId).AutomationElement; // Find Option (One or Many) to be found var findOption = FindOptionFactory.Get(request.FindOption); // Tree scope where elements should be found var treeScope = TreeScopeFactory.Get(request.SearchScope); // Create condition (Single or Multi) Condition condition = null; if (request.PropertyConditionModels.Count == 1) { var propertyConditionModel = request.PropertyConditionModels[0]; condition = ConditionFactory.Get(propertyConditionModel.Name, propertyConditionModel.Value); } else if (request.PropertyConditionModels.Count > 1) { var propertyConditions = (from pc in (request.PropertyConditionModels) select ConditionFactory.Get(pc.Name, pc.Value)).ToArray(); condition = new AndCondition(propertyConditions); } // Select find style (First or Many) Automation Elements to be found if (findOption == FindOption.FindFirst) { var automationElement = baseNode.FindFirst(treeScope, condition); results.Add(_automationElementRepository.Save(automationElement)); } else { var automationElements = baseNode.FindAll(treeScope, condition).OfType <AutomationElement>().ToList(); results.AddRange(automationElements.Select(ae => _automationElementRepository.Save(ae))); } return(new LocateAutomationElementResponse { AutomationElementWrappers = new List <AutomationElementWrapper>(results) }); }