public static void WaitForSpinner(this IWebDriver driver, By locator)
        {
            bool isSpinnerInvisible = Poller.PollForSuccess(() => !driver.IsElementDisplayed(locator));

            if (!isSpinnerInvisible)
            {
                throw new Exception("Spinner is still present after waiting");
            }
        }
        public static void WaitForSpinners(this IWebDriver driver, By locator)
        {
            bool AreAllSpinnersInvisible()
            {
                ReadOnlyCollection <IWebElement> spinnerElements = driver.FindElements(locator);

                return(spinnerElements.None(e => e.Displayed));
            }

            bool allSpinnersAreInvisible = Poller.PollForSuccess(() => FunctionRetrier.RetryOnException <bool, StaleElementReferenceException>(AreAllSpinnersInvisible));

            if (!allSpinnersAreInvisible)
            {
                throw new Exception("Spinners are still present after waiting");
            }
        }
        public static bool PollForMatch <TComparisonItem>(
            this TableRow row,
            Func <TComparisonItem> getComparisonData,
            Func <TComparisonItem, TableRow, bool> isMatchingRow,
            int maxNumChecks        = 10,
            int waitIntervalSeconds = 2)
        {
            bool Match()
            {
                TComparisonItem comparisonItem = getComparisonData();

                return(isMatchingRow(comparisonItem, row));
            }

            bool foundMatch = Poller.PollForSuccess(Match, maxNumChecks, waitIntervalSeconds);

            return(foundMatch);
        }
        public static IList <IWebElement> GetElementsWhenVisible(this IWebDriver driver, By locator)
        {
            IWebElement[] foundVisibleElements = Array.Empty <IWebElement>();

            IWebElement[] WebDriverActions() => driver.FindElements(locator).Where(e => e.Displayed).ToArray();

            Poller.PollForSuccess(() =>
            {
                foundVisibleElements = FunctionRetrier.RetryOnException <IWebElement[], StaleElementReferenceException>(WebDriverActions);
                return(foundVisibleElements.Any());
            });

            if (foundVisibleElements.None())
            {
                throw new Exception($"No visible elements found for locator {locator}");
            }

            return(foundVisibleElements);
        }
        public static IReadOnlyCollection <TableRow> PollForUnmatchedRows <TComparisonItem>(
            this IEnumerable <TableRow> rows,
            Func <IEnumerable <TComparisonItem> > getComparisonData,
            Func <TComparisonItem, TableRow, bool> isMatchingRow,
            int maxNumChecks        = 10,
            int waitIntervalSeconds = 2)
        {
            List <TableRow> unmatchedRows = new List <TableRow>();

            bool FindUnmatchedRows()
            {
                IEnumerable <TComparisonItem> comparisonItems = getComparisonData();

                unmatchedRows = rows
                                .Where(row => comparisonItems.None(c => isMatchingRow(c, row)))
                                .ToList();

                return(unmatchedRows.None());
            }

            Poller.PollForSuccess(FindUnmatchedRows, maxNumChecks, waitIntervalSeconds);

            return(unmatchedRows);
        }