Bean0341
Bean0341

Reputation: 1697

Thread.sleep() being ignored by selenium C#

I have a selenium test that works great while debugging and stepping slowly through. I added a Thread.Sleep() in order to stop selenium while a file is downloaded. However selenium in completely ignoring the Thread.Sleep(). Any thoughts?

IWebElement iframe = driver.FindElement(By.Id("genFrame"));
CurrentFrame = driver.SwtichTo();
CurrentFrame.Frame(iframe);
driver.FindElement(By.Id("date").Sendkeys("05/11/2021" + Keys.Enter));
driver.FindElement(By.Id("export-btn"));
System.Thread.Sleep(5000);

Upvotes: 1

Views: 516

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193258

In all possibilities System.Thread.Sleep() is never ignored unless some previous line of code raises an exception.


As per your code the unit is milliseconds, so effectively 5000 milliseconds, i.e. 5 seconds.


Solution

You may like to increase the waiting time to greater value, e.g. 10 seconds or more:

using System;  
using System.Threading;

System.Thread.Sleep(10000);

Update

As you can visually see selenium add the date field, possibly the line in the mid:

driver.FindElement(By.Id("export-btn"));

raises an exception.

Upvotes: 1

Related Questions