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 impression that if it does not find the element it just goes back to through the loop again. I believe the explanation is pretty simple... Could anyone enlighten me?
public static void selectFromList(String vList, String vText, IWebDriver driver)
{
for (int sec = 0; ; sec++)
{
System.Threading.Thread.Sleep(2500);
if (sec >= 10) Debug.Fail("timeout : " + vList);
if (driver.FindElement(By.Id(ConfigurationManager.AppSettings[vList])).Displayed) break;
}
new SelectElement(driver.FindElement(By.Id(ConfigurationManager.AppSettings[vList]))).SelectByText(vText);
}