how to wait until the textbox enable in watin

后端 未结 4 1527
予麋鹿
予麋鹿 2021-01-29 02:10

i have one textbox on my page on the load event textbox is disable for 10 then its enable so how to wait for 10 sec in watin. i am try to this code

IE ie = new I         


        
4条回答
  •  悲哀的现实
    2021-01-29 02:20

    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;
        }
    }
    

提交回复
热议问题