// Click action and wait until field selector stops returning an element
        // must exist before action is invoked
        public static void ClickAndWaitGone(this SafeWebDriverWait wait, IWebElement action, string fieldSelector, int delay = 0)
        {
            if (delay > 0)
            {
                Thread.Sleep(delay);
            }
            IWebElement field = wait.Driver.FindElement(By.CssSelector(fieldSelector));

            Assert.IsNotNull(field);
            action.Click();
            wait.Until(wd => (field = SafeFunc(() => wd.FindElement(By.CssSelector(fieldSelector)))) == null);
            Assert.IsNull(field);
        }
        // Click action and wait unitil field selector returns an element
        public static IWebElement ClickAndWait(this SafeWebDriverWait wait, IWebElement action, string fieldSelector, int delay = 0)
        {
            if (delay > 0)
            {
                Thread.Sleep(delay);
            }
            action.Click();
            IWebElement field = null;

            wait.Until(wd => (field = wd.FindElement(By.CssSelector(fieldSelector))) != null);
            Assert.IsNotNull(field);
            return(field);
        }
        private static void ClickClearContextMenu(this SafeWebDriverWait wait, int index, ClearType clearType)
        {
            var tabCount = wait.Driver.FindElements(By.CssSelector(".nof-tab")).Count;
            var newCount = clearType == ClearType.ClearThis ? tabCount - 1 : clearType == ClearType.ClearOthers ? 1 : 0;

            var webDriver = wait.Driver;
            var tab       = webDriver.FindElements(By.CssSelector(".nof-tab"))[index];
            var loc       = (ILocatable)tab;
            var mouse     = ((IHasInputDevices)webDriver).Mouse;

            mouse.ContextClick(loc.Coordinates);

            var selector = string.Format(".ui-menu-item:nth-of-type({0}) a", (int)clearType);

            wait.Until(wd => wd.FindElement(By.CssSelector(selector)));
            wait.ClickAndWait(selector, wd => wd.FindElements(By.CssSelector(".nof-tab")).Count == newCount);
        }
 // click action then wait until f returns true
 public static void ClickAndWait(this SafeWebDriverWait wait, IWebElement action, Func <IWebDriver, bool> f)
 {
     action.Click();
     wait.Until(f);
 }
        // find then click action then wait until f returns true
        public static void ClickAndWait(this SafeWebDriverWait wait, string actionSelector, Func <IWebDriver, bool> f)
        {
            IWebElement action = wait.Driver.FindElement(By.CssSelector(actionSelector));

            wait.ClickAndWait(action, f);
        }
        // Find then click action and wait until field selector stops returning an element
        public static void ClickAndWaitGone(this SafeWebDriverWait wait, string actionSelector, string fieldSelector, int delay = 0)
        {
            IWebElement action = wait.Driver.FindElement(By.CssSelector(actionSelector));

            wait.ClickAndWaitGone(action, fieldSelector);
        }
 public static void ClickClearAll(this SafeWebDriverWait wait, int index)
 {
     wait.ClickClearContextMenu(index, ClearType.ClearAll);
 }