While creating test scripts in Selenium WebDriver using C#, I have used Explicit wait (after going through this link) and have also gone through SO and SQA links for the same. So, I implemented it like this:
Class1.cs
namespace SeleniumProject {
public class WaitClass
{
public static void WaitForElementLoad(FirefoxDriver driver, By by, int timeoutInSeconds)
{
//string name = "TEST";
if (timeoutInSeconds > 0)
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
wait.Until(ExpectedConditions.ElementIsVisible(by));
}
}
} }
and then used it in Class2.cs
namespace SeleniumProject
{
[TestClass]
public class StartTesting
{
public static FirefoxDriver driver;
[TestMethod]
public static void Main(string[] args)
{
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.test.com/");
driver.Manage().Window.Maximize();
String title = driver.Title;
int timeinterval = 10;
driver.FindElement(By.LinkText("Test Link")).Click();
WaitClass.WaitForElementLoad(driver, By.LinkText("Child Test link 2"), timeinterval);
driver.FindElement(By.LinkText("Child Test link 2")).Click();
//System.Threading.Thread.Sleep(3000);
WaitClass.WaitForElementLoad(driver, By.Name("firstname"), timeinterval);
driver.FindElement(By.Name("firstname")).SendKeys(Firstname);
but, using it this way I get an error message for the Class1, frequency of this error is like 2 out of 10 iterations, because of this I have a feeling that either this is not a good + reliable method for explicit wait or I am doing something wrong here. I was earlier using Timeinterval as 5 secs. but after this error I changed it to 10 seconds and still getting same error randomly.
Error which I get is: