Reputation: 1126
I am using Selenium to login to a webpage and get to what would be that site's "homepage." In most cases I use a call to:
IWebDriver driver = new FirefoxDriver;
driver is declared much earlier, but I have it here for reference.
diver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(<insert time here>);
Normally, this will be all I need and then the code will do what I want it to do. However, in this case the login page goes through a few different "http://..." links so waiting for a page to load will not suffice, as it goes through many. I know I need to use the Timer class to wait for the last link, but not quite sure how to use it properly. Can someone explain how to properly use the Timer() class to get the result I want?
Upvotes: 0
Views: 1897
Reputation: 716
You can test timing on individual operations with a WebDriverWait
object.
try
{
var wait = new WebDriverWait(YourWebDriverInstance, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(driver => driver.FindElement(By.Name("q")));
}
catch (WebDriverTimeoutException ex)
{
// handle timeout
}
Upvotes: 1
Reputation: 1126
I have found a solution that I initially overlooked. I am posting it here for anyone who also may run into this problem in the future and finds this thread. This code works, but its very specific and not the best solution.
Thread.Sleep(TimeSpan.FromSeconds(30));
This will halt the thread/script from running for exactly 30 seconds. It works in my case because my internet speed is fast enough, but it is not ideal, for it is possible the pages could take more than 30 seconds to load, resulting in a crash in the code. I am still open to suggestions if anyone has one.
Upvotes: 0