0

I have written below code to make test script wait till some of my elements get loaded. But what if, that element will never get loaded? That means if TopWorkOrderCard.Displayed will never get displayed, then my loop will be a never ending loop.

How to handle situations like this?

sample code:

public void WaitforWOlist(int WaitTime)
        {
            try
            {

                    if (TopWorkOrderCard.Displayed == true)
                    {
                        //do nothing
                    }


            }
            catch (Exception)
            {
                Thread.Sleep(WaitTime);

                WaitforWOlist(2000);


            }
1

Try something like this

 public void WaitforWOlist(int WaitTime, int counter)
   {
    if (counter > 20)
    {
        return;
    }
    try
    {
        if (TopWorkOrderCard.Displayed == true)
        {
            //do nothing
        }
    }
    catch (Exception)
    {
        Thread.Sleep(WaitTime);
        WaitforWOlist(2000, counter + 1);

    }
|improve this answer|||||
  • This seems OK. we can set the counter ...Thanks – ChathuD Nov 23 '16 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.