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); }
private static IDOMRoot SafeGetDOMRoot(ElementsContainer otherElement, string paramName) { if (otherElement == null) { throw new ArgumentNullException(paramName); } return(otherElement.DOMRoot); }
private static IWebElement GetWebElement(ElementsContainer elementsContainer, By @by, Func <IReadOnlyCollection <IWebElement>, IWebElement> selector) { 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); return(selector(matchingElements)); }
/// <summary> /// Initialized a new instance of <see cref="BrowserElement"/> given its container, a specific 'By' filter and description /// </summary> /// <param name="container">The container that contains the relevant element. Typically this is a <see cref="Browser"/>, <see cref="BrowserWindow"/>, <see cref="Frame"/> or a containing <see cref="BrowserElement"/></param> /// <param name="by">A filter mechanism used to find the element. If multiple elements match the filter, the first one is used</param> /// <param name="description">The description of the new element</param> /// <exception cref="ArgumentNullException">Any of the arguments is null</exception> public BrowserElement(ElementsContainer container, By by, string description) : this(SafeGetDOMRoot(container, "container"), () => container.GetSearchContext().FindElement(by), description) { }
/// <summary> /// Initializes a new instance of <see cref="BrowserElement"/> given its container, a 'By' filter a selector and description /// </summary> /// <param name="container">The container that contains the relevant element. Typically this is a <see cref="Browser"/>, <see cref="BrowserWindow"/>, <see cref="Frame"/> or a containing <see cref="BrowserElement"/></param> /// <param name="by">A filter mechanism used to filter the matching elements</param> /// <param name="selector">A delegate that is used to select the sepecific element from the filtered elements</param> /// <param name="description">The description of the new element</param> /// <exception cref="ArgumentNullException">Any of the arguments is null</exception> public BrowserElement(ElementsContainer container, By by, Func<IReadOnlyCollection<IWebElement>, IWebElement> selector, string description) : this(SafeGetDOMRoot(container, "container"), () => GetWebElement(container, by, selector, description), description) { }
private static IDOMRoot SafeGetDOMRoot(ElementsContainer otherElement, string paramName) { if (otherElement == null) throw new ArgumentNullException(paramName); return otherElement.DOMRoot; }
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; }
/// <summary> /// Initializes a new instance of <see cref="BrowserElement"/> given its container, a 'By' filter a selector and description /// </summary> /// <param name="container">The container that contains the relevant element. Typically this is a <see cref="Browser"/>, <see cref="BrowserWindow"/>, <see cref="Frame"/> or a containing <see cref="BrowserElement"/></param> /// <param name="by">A filter mechanism used to filter the matching elements</param> /// <param name="selector">A delegate that is used to select the sepecific element from the filtered elements</param> /// <param name="description">The description of the new element</param> /// <exception cref="ArgumentNullException">Any of the arguments is null</exception> public BrowserElement(ElementsContainer container, By by, Func <IReadOnlyCollection <IWebElement>, IWebElement> selector, string description) : this(SafeGetDOMRoot(container, "container"), () => GetWebElement(container, by, selector, description), description) { }