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 Answer 1

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

    }
1
  • This seems OK. we can set the counter ...Thanks
    – ChathuD
    Nov 23, 2016 at 3:35

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .