WebDriver and C# - NoSuchElement exception

后端 未结 3 1975
天命终不由人
天命终不由人 2021-01-13 06:29

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

3条回答
  •  感动是毒
    2021-01-13 06:41

    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);
    }
    

提交回复
热议问题