2

I added some breakpoint My test works in debug mode. But after deleting breakpoints I get Timeout exception. I used Thread.Sleep and it worked are there any alternatives rather than using thread.sleep

        [Test]
        public void OpenStockControl()
        {
            driver.Navigate().GoToUrl("http://testdeneme.com");
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
            IWebElement userName = driver.FindElement(By.Id("LoginNew1_tU"));
            userName.SendKeys("TEST3");
            IWebElement userPassword = driver.FindElement(By.Id("LoginNew1_tP"));
            userPassword.SendKeys("A7535");
            IWebElement buttonSubmit = driver.FindElement(By.Id("LoginNew1_bGo"));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
            buttonSubmit.Click();

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
            SwitchWindow("ABC MA", driver);
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));

            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("ext-gen54")));
            element.Click();

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            IWebElement element2 = wait.Until(ExpectedConditions.ElementExists(By.Id("ext-gen207")));
            element2.Click();

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            IWebElement element3 = wait.Until(ExpectedConditions.ElementExists(By.Id("ext-gen260")));
            element3.Click();
        }
4
  • We will need to see an example. Show us some code that is failing. If you are using Sleeps and they work, it means that you have timing issues and should be correctly waiting for specific things to occur or happen on the page. Commented Apr 11, 2014 at 8:51
  • Thanks, I added my example. This way it doesn't work... Commented Apr 11, 2014 at 12:03
  • 1
    Does it fail somewhere in particular consistently? Also, you should be aware that calling driver.Manage().Timeouts().ImplicitlyWait() doesn't actually wait like a Thread.sleep() does, it just sets the drivers maximum wait time for implicit waits. Just calling it once at the start of your code (with 20 second parameter passed in) is sufficient. Read up on ImplicitlyWait and the WebDriverWait class Commented Apr 11, 2014 at 14:42
  • It fails in the last step. It can't find the last element. Commented Apr 13, 2014 at 11:26

2 Answers 2

1

Your waits (WebDriverWait) are waiting for 10 seconds for elements to appear. ExpectedCondition is not met and thus the Exception is thrown. You can increase the time amount in your call of WebDriverWait constructor.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you looked at http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp ? I have found that adding my own methods like bool WaitForPage([WebDriver],[Page],[time]) and its corollary WaitForNotPage(...) resolved many of the timeout issues. Explicit waits and implicit waits do solve many of them but you will still find yourself occasionally using Thread.Sleep().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.