public bool Missing(By by)
        {
            SearchOptions options = by.GetSearchOptionsOrDefault();

            bool FindNoElement(T context)
            {
                return(options.Visibility == Visibility.Any
                    ? !context.FindElements(by).Any()
                    : !context.FindElements(by).Any(CreateVisibilityPredicate(options.Visibility)));
            }

            Stopwatch searchWatch = Stopwatch.StartNew();

            bool isMissing = Until(FindNoElement, options.ToRetryOptions());

            searchWatch.Stop();

            if (!options.IsSafely && !isMissing)
            {
                throw ExceptionFactory.CreateForNotMissingElement(
                          new SearchFailureData
                {
                    By            = by,
                    SearchTime    = searchWatch.Elapsed,
                    SearchOptions = options,
                    SearchContext = Context
                });
            }
            else
            {
                return(isMissing);
            }
        }
        private ReadOnlyCollection <IWebElement> FindAll(By by, SearchOptions options = null)
        {
            options = options ?? by.GetSearchOptionsOrDefault();

            Func <T, ReadOnlyCollection <IWebElement> > findFunction;

            if (options.Visibility == Visibility.Any)
            {
                findFunction = x => x.FindElements(by);
            }
            else
            {
                findFunction = x => x.FindElements(by).
                               Where(CreateVisibilityPredicate(options.Visibility)).
                               ToReadOnly();
            }

            return(Until(findFunction, options.ToRetryOptions()));
        }
        private IWebElement Find(By by)
        {
            SearchOptions options = by.GetSearchOptionsOrDefault();

            ReadOnlyCollection <IWebElement> lastFoundElements = null;

            IWebElement FindElement(T context)
            {
                lastFoundElements = context.FindElements(by);

                return(options.Visibility == Visibility.Any
                    ? lastFoundElements.FirstOrDefault()
                    : lastFoundElements.FirstOrDefault(CreateVisibilityPredicate(options.Visibility)));
            }

            Stopwatch searchWatch = Stopwatch.StartNew();

            IWebElement element = Until(FindElement, options.ToRetryOptions());

            searchWatch.Stop();

            if (!options.IsSafely && element == null)
            {
                throw ExceptionFactory.CreateForNoSuchElement(
                          new SearchFailureData
                {
                    By            = by,
                    SearchTime    = searchWatch.Elapsed,
                    SearchOptions = options,
                    AlikeElementsWithInverseVisibility = lastFoundElements,
                    SearchContext = Context
                });
            }
            else
            {
                return(element);
            }
        }