I would like to use the selenium2 c# webdriver to test our login mechanism. The following test passes if I run through it in debug mode and give the Click method some time. If I run it normally though the test fails with a NoSuchElementException.
[Test]
public void TestClickLogonLink()
{
_driver.Navigate().GoToUrl("http://nssidManager.local/");
IWebElement loginElement = _driver.FindElement(By.Id("loginWidget"));
IWebElement logonAnchor = loginElement.FindElement(By.LinkText("Log On"));
logonAnchor.Click();
IWebElement userNameTextBox = _driver.FindElement(By.Id("UserName"));
Assert.IsNotNull(userNameTextBox);
}
How do I need to tell Selenium to Wait until the logonAnchor.Click has finished loading the next page?
Set the implicit wait like so:
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0,30));
This will allow Selenium to block until the FindElement succeeds or times out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With