I am looking for some suggestions on how to deal with a slight timing issue that I am having with two controls on a page. I have a list box that contains up to 10 items, however the contents of the box can change depending on what characters are entered into the search box.
For example: I enter zi into the search box and the list box will begin to populate Zimmerman...
The trouble that I am running into is that there is enough of a delay between entering the text and when I use WatiN to click the button to change the view to that of the top item in the list.
So here is what I currently have in my
browser.Page<AVDashboardPage>().SearchBox.TypeText("zi");
browser.Page<AVDashboardPage>().ChangeActBtn.Click();
What I am considering doing is to simply write a small method in the AVDashboard page class that contains a small delay.
public void EnterSearchTextWithDelay(string searchText)
{
SearchBox.TypeText(searchText);
System.Threading.Thread.Sleep(200);
}
I suppose I could also do it by adding a while loop that would look in the listbox for a corresponding element but I worry that could be pretty slow.
So my method ended up looking like this:
public void EnterSearchTextWithDelay(string searchText)
{
SearchBox.TypeText(searchText);
int counter = 0;
while(!AccountList.Text.Contains(searchText) && counter < 50)
{
System.Threading.Thread.Sleep(10);
counter++;
}
}