Custom wait functionality for detecting elements in a WebPage
The below one is a custom wait functionality that can be used to detect element in Selenium.And it’s usage has been also declared below.
All we have to do is declare this as part of a static class and use it somewhere
Real Function:
//Usage- LongLongWaitTime can be declared somewhere Browser.FindElement(By.XPath("//div[@id='totalrow']"), LongLongWaitTime).Click() //You can also pass seconds Browser.FindElement(By.ID("totalrow"), 30).Click() //Function public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds) { if (timeoutInSeconds > 0) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return wait.Until(drv => drv.FindElement(by)); } else { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); return wait.Until(drv => drv.FindElement(by)); } }