JavaEar 专注于收集分享传播有价值的技术资料

"OpenQA.Selenium.WebDriverTimeoutException: 'Timed out after 40 seconds'

I'm trying to Code in Selenuim with C# for a website, after Username it's getting time out with the message

OpenQA.Selenium.WebDriverTimeoutException: 'Timed out after 40 seconds'

Here is my code which I'm referring to.

  //Enter user info
  SetMethods.EnterText(driver, "Username", "svedanth", "ID");
  SetMethods.EnterText(driver, "Password", "openopen", "ID");

  SetMethods.Click(driver, "Next", "ID");

  //Thread.Sleep(TimeSpan.FromSeconds(5));
  wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(
  By.XPath(".//*[@id='logOnContainer']/form/div[1]/button")));

1个回答

    最佳答案
  1. Create a new WebDriverWait like so:

    WebDriverWait customWait = new WebDriverWait(driver,TimeSpan.FromMinutes(5));
    

    and do

    customWait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.XPath(".//*[@id='logOnContainer']/form/div[1]/button")));
    

    when you initialized your wait at some point in your code, you probably set the timeout at 40 seconds.

    The reason you have your problem, is because 40 seconds pass and your elements are still not visible. After they are all visible, program stop "waiting" and will continue with the rest of the code.

    If you will, you can set your own timeout by changing the TimeSpan I gave in my example.