private static IWebElement GetWebElement(ElementsContainer elementsContainer, By by, Func <IReadOnlyCollection <IWebElement>, IWebElement> selector, string description)
{
if (elementsContainer == null)
{
throw new ArgumentNullException("elementsContainer");
}
if (by == null)
{
throw new ArgumentNullException("by");
}
if (selector == null)
{
throw new ArgumentNullException("selector");
}
var searchContext = elementsContainer.GetSearchContext();
var matchingElements = searchContext.FindElements(by);
var selectedElement = selector(matchingElements);
if (selectedElement == null)
{
throw new NoSuchElementException(string.Format("Element '{0}' could not be found or is not available", description));
}
return(selectedElement);
}