internal List <Element> FindElements(Element ParentElement, ObjectMappingDetails Mapping) { int index = 0; List <IWebElement> FoundElements; List <Element> returnList = new List <Element>(); if (ParentElement == null) { return(FindElements(Mapping)); } else { By SeleniumFindBy = Mapping.SeleniumBy; Logger.Write(Logger.LogLevels.FrameworkDebug, "Find Elements: Name - [{0}], Selenium logic - [{1}]", Mapping.FriendlyName, SeleniumFindBy.ToString()); try { FoundElements = ParentElement.WebElement.FindElements(SeleniumFindBy).ToList(); } catch (Exception ex) { throw new SeleniumFindElementError(Mapping, ParentElement, ex); } Logger.WriteLine(Logger.LogLevels.FrameworkDebug, " (Found [{0}] elements)", FoundElements.Count.ToString()); // // Our find logic has returned a bunch of elements. We _may_ want to use the find logic of a specific element again. So, when saving the elements add // an indexer to the ActualFindLogic..... // FoundElements.ForEach(iWebElement => { ObjectMappingDetails thisMapping = Mapping.Copy(); thisMapping.FriendlyName = string.Format("{0}[{1}]", thisMapping.FriendlyName, index.ToString()); if (thisMapping.FindType == ObjectMappingDetails.ByType.XPath) { thisMapping.FindLogicUsed = string.Format("({0})[{1}]", thisMapping.FindLogic, index.ToString()); } Element Element = new Element(ParentElement, iWebElement, thisMapping); returnList.Add(Element); index++; }); return(returnList); } }
public List <Element> FindElements(ObjectMappingDetails Mapping) { int index = 0; List <IWebElement> FoundElements; List <Element> returnList = new List <Element>(); // // Get the Selenium By and perform the Selenium FindElements from the top level to get a list of matching elements // By SeleniumFindBy = Mapping.SeleniumBy; Logger.Write(Logger.LogLevels.FrameworkInformation, "Find Elements: {0}", SeleniumFindBy.ToString()); try { FoundElements = webDriver.FindElements(SeleniumFindBy).ToList(); } catch (Exception ex) { throw new SeleniumFindElementError(Mapping, this, ex); } Logger.WriteLine(Logger.LogLevels.FrameworkInformation, " (Found [{0}] elements)", FoundElements.Count.ToString()); // // Now go through the list and bind each iWebElement to the framework element. // FoundElements.ForEach(iWebElement => { ObjectMappingDetails thisMapping = Mapping; if (thisMapping.FindType == ObjectMappingDetails.ByType.XPath) { thisMapping.FindLogicUsed = string.Format("({0})[{1}]", thisMapping.FindLogic, index.ToString()); } Element Element = new Element(this, iWebElement, thisMapping); returnList.Add(Element); index++; }); return(returnList); }