how to wait until the textbox enable in watin

感情迁移 提交于 2019-12-02 09:29:34

You can just sleep the thread for a fixed amount of time in order for the test to wait:

            System.Threading.Thread.Sleep(10000);

The time is in milliseconds. Maybe you would need to increase that number a little bit, but still this should work.

If it is ran when the webpage loads you could probably just use this:

ie.WaitForComplete();

Wait for complete will make the test wait until all of the elements and frames are loaded before carrying out the next task, in your case locating the textbox for input.

The only problem I have with putting the thread to sleep is that it can take a bit longer than you may need. This way you know it is running as soon as the page is done. (Which may vary a bit).

Two better ways than just using a long Thread.Sleep() to wait for fields to enable due to a script or asnyc call; eg Ajax. (Note: I'd be ashamed to admit how many long Thread.Sleeps() I have in my code.)

The below are both referencing a checkbox, but the same concepts should work just fine on a textbox or other control.

1) Check the disabled attribute.

myPage.myCheckbox.WaitUntil("disabled", false.ToString())

2) Poll the field, sleeping a short amount of time at each check. I did this poll pattern as the above simple one liner above didn't work; I don't remember why as it has been quite a while.

int sleepTime = 100;
int numberOfPolls = 50;

for (int i = 0; i < 50; i++)
{
    if (myPage.myCheckbox.Enabled == false)
    {
        Thread.Sleep(100);
    }
    else
    {
        break;
    }
}

You could try this...

ie.Element("TextBox1").WaitUntil<Element>(element => element.Enabled);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!