Thread.sleep() 被 selenium C# 忽略
我有一个硒测试,可以在调试和缓慢踏上逐步调试和踏入时效果很好。我添加了一个thread.sleep()
,以便在下载文件时停止硒。但是,硒完全忽略thread.sleep()
。有什么想法吗?
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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在所有可能性中,
System.Thread.Sleep()
永远不会被忽略,除非前面的某些代码行引发了异常。根据您的代码,单位为毫秒,因此实际上是5000毫秒,即5秒。
解决方案
您可能希望将等待时间增加到更大的值,例如10秒或更长:
更新
正如您可以直观地看到selenium添加了日期字段,可能是中间的行:
引发异常。
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:
Update
As you can visually see selenium add the date field, possibly the line in the mid:
raises an exception.