Bean0341
Bean0341

Reputation: 1697

Selenium wait issue

I have an input box that pulls an autocomplete list. The list is a little slow to pull, so I need selenium to just wait before pressing the enter key, which will select the first item in the list. here is what I have so far

            webDriver.FindElement(By.Id("seg-gl-1")).SendKeys("2");
            webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            webDriver.FindElement(By.Id("seg-gl-1")).SendKeys(Keys.Enter);

The issue is that selenium is hitting Enter too quickly. I believe I am using the implicitwait incorrectly. Can anyone shed some light on my issue?

Upvotes: 2

Views: 89

Answers (1)

Agent Shoulder
Agent Shoulder

Reputation: 585

When you use

webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

You are only setting the default ImplicitWait time. If you want to actually perform a wait for, lets say 10sec, you could use

System.Threading.Thread.Sleep(5000);

Generally you should avoid this type of wait, but I'm guessing that there are javascript/ajax calls performed in the background of your application, and hence you should wait for these to execute before being able to assert the site behaviour (as these calls might update the DOM and such). For further help on that, please refer to my answer in this thread: https://stackoverflow.com/a/45033412/6220192

Upvotes: 1

Related Questions