public static Func <IWebDriver, IWebElement> ElementIsVisible(By locator)
 {
     return(delegate(IWebDriver driver)
     {
         IWebElement result;
         try
         {
             result = ExpectedConditions.ElementIfVisible(driver.FindElement(locator));
         }
         catch (StaleElementReferenceException)
         {
             result = null;
         }
         return result;
     });
 }
 public static Func <IWebDriver, IWebElement> ElementToBeClickable(By locator)
 {
     return(delegate(IWebDriver driver)
     {
         IWebElement webElement = ExpectedConditions.ElementIfVisible(driver.FindElement(locator));
         IWebElement result;
         try
         {
             if (webElement != null && webElement.Enabled)
             {
                 result = webElement;
             }
             else
             {
                 result = null;
             }
         }
         catch (StaleElementReferenceException)
         {
             result = null;
         }
         return result;
     });
 }