I have the following code for selecting an option from given list and it usually works, but sometimes it fails with NoSuchElement exception on the second if. I was under the
You could try one of the answers from this SO question:
public static IWebElement FindElement(this IWebDriver driver, String vList, String vText, int timeoutInSeconds)
{
By selector = By.Id(ConfigurationManager.AppSettings[vList])
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => drv.FindElement(selector));
}
return driver.FindElement(selector);
}