Instead of: driver.Url = " Thread.Sleep(5000) So now you can write: driver.Url = " IWebElement myDynamicElement = driver.FindElement(By.Id("someDynamicElement")) This way you're telling Selenium to wait up to 5 seconds when it tries to find an element or interact with the page. This is how you set an implicit wait: WebDriver driver = new FirefoxDriver() ĭriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)) Once set, the implicit wait is set for the life of the WebDriver object instance. In cases like this you can use Implicit Waits:Īn implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. If all of your pages take around the same time to load, which is longer than expected, then most tests are going to fail due to untimely response. We are going to discuss two types of delays which should cover pretty much all cases you have to deal with: adding a global delay and waiting for something to happen. Here I am going to show you how to avoid inserting fixed delays in your tests. You see, there is no winning with arbitrary delays: you either get a slow or a brittle test suite.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |