Exemple #1
0
        /// <summary>
        /// This method evaluates if one IWebElement contains a child selected by the predicate. It can be used to select
        /// one container element based on its child elements.
        /// </summary>
        /// <param name="element">The container element to be evaludated.</param>
        /// <param name="childEnum">Enum Identifier of the child element, which carries the CSS selector.</param>
        /// <param name="predicate">Function to see if the child element meets predefined criteria.</param>
        /// <returns>"true": The container IWebElement contains the expected child IWebElement, otherwise "false".</returns>
        public static bool HasChildOf(this IWebElement element, Enum childEnum, Func <IWebElement, bool> predicate)
        {
            string      childLocatorCss = childEnum.Css();
            IWebElement child           = null;

            try
            {
                //child = GenericWait<IWebElement>.Until(() =>
                //    element.FindElementByCss(childLocatorCss), null, 1000);
                ReadOnlyCollection <IWebElement> candidates = null;
                candidates = GenericWait <ReadOnlyCollection <IWebElement> > .Until(
                    () => candidates = element.FindElementsByCss(childLocatorCss),
                    x => x.Count != 0,
                    200
                    );

                var  qualified = candidates.Where(predicate).ToList();
                bool result    = qualified.Count != 0;
                return(result);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #2
0
 /// <summary>
 /// Assuming Elements can be found with CSS selector within time specified by waitInMills, keep executing the
 /// FindElementsByCssSelector() of either Driver or a specific IWebElement until timeout.
 /// </summary>
 /// <param name="findFunc">The FindElementsByCssSelector() of either Driver or a specific IWebElement.</param>
 /// <param name="css">CSS Selector string.</param>
 /// <param name="waitInMills">Maximum time to wait when the findFunc returns 0-length collection.</param>
 /// <returns>The non-empty collection immediately or empty collection after time is out.</returns>
 public ReadOnlyCollection <IWebElement> WaitToFindElements(Func <string, ReadOnlyCollection <IWebElement> > findFunc,
                                                            string css,
                                                            int waitInMills)
 {
     return(GenericWait <ReadOnlyCollection <IWebElement> > .Until(
                () => findFunc(css), collction => collction.Count != 0, waitInMills
                ));
 }