Selenium C# Timeout Exception Selenium C# Timeout Exception selenium selenium

Selenium C# Timeout Exception


You're getting the Timeout error because you have added the implicit wait.Let's take it on your example:

var driver = new ChromeDriver();driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1000));driver.FindElement(By.XPath(".//div[@class='modal fade in']//button[text()='Close']")).Click();

In this case, you're 'telling' Selenium to wait the specified timeout before it will search the element you want to be found. If the element was not found, you will get the Timeout error.

var driver = new ChromeDriver();driver.FindElement(By.XPath(".//div[@class='modal fade in']//button[text()='Close']")).Click();

In this case you're telling Selenium to get the element automatically, so in case it will not be found, you will get a NoSuchElementException, with no timeouts because there's no time to wait before the element to be present.

And if we're expanding it to the Explicit wait:

var driver = new ChromeDriver();var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 1000));wait.Until(d => d.FindElement(By.XPath(".//div[@class='modal fade in']//button[text()='Close']"))).Click();

In this case you're telling Selenium to keep searching for the element until it is found but no longer than the maximum timeout specified as a param to WebDriverWait.