Forum Discussion

nbenitus's avatar
nbenitus
Contributor
14 years ago

How to wait for a listbox to be non-empty

Hi,



In my testcase, I am trying to do some operations on a list box. The listbox is initially empty, then there is some information that gets displayed in it.



In my script, I am waiting for the listbox to be non-empty (or wItemCount > 0). Here is the line I am using:



Call lstDirectory.WaitProperty("wItemCount", ?, 20000)



However, I don't know what to put as second parameter (displayed as "?").



I have tried the following: >0, <>0 and many similar entries, without luck.



Thank you in advance.



Note: I am using Vbscript.

4 Replies

  • Not sure if you're using a WPF listbox, but I believe they have a "HasItems" property that will be true/false depending on whether it's empty or not.
  • If you aren't, you could try something like this:



    While lstBox.Items.Count = 0

         BuiltIn.Delay(1000)

         lstBox.Refresh     <---  not sure if you need that or not

    WEnd
  • Thank you for your answer!



    I checked and my object does not have the HasItems property, unfortunately.



    The while loop was my next option, but I was wondering if there was a way to use the WaitProperty function in this scenario.
  • Hello Benoit,


    The WaitProperty method waits until the property gets the specified value. That is, it will work for you only if you know the exact number of the items the list box control will have. This number should be used as the second parameter of the method.

    If your list box control can have different number of items, using a loop as Charles suggested is your only option.