Forum Discussion

autopunk2007's avatar
autopunk2007
Occasional Contributor
14 years ago

Silverlight Object hierachy becomes misaligned/jumbled when scroll methods are invoked.

I'm in the process of building a function that can select an item in a SilverLight listbox by its text value(textblock object which is a child of a list box item).

SilverLight only loads the the textblock objects for the list items that are visible on screen.

For example, if a list has "Item 1" to "Item 100" and only 10 are viewable on screen at any one time and only 10 items will have textblock objects in the object tree.

So, in order to interogate the rest of the 90 items, we need to scroll down so that they are loaded into the object tree.

This is easy to do, since UIAutomation provides methods and properties for scrolling.


However, the object hierachy in TestComplete becomes completely misaligned (jumbled) as we scroll down the list...

E.g.

  - Before scrolling, Item 3 has a textblock of "Item 3".

  - After scrolling and looking at this in the object browser, it has "Item 17".

Therefore, trying to select "Item 3" (using the addToSelection method on it's parent), selects a random item...


Have tried using Sys.Refresh, Sys.Process("...").Refresh, and object.refresh everywhere, but to no avail.

I suspect this is a TestComplete issue, since shutting down TestComplete completely and reopening TestComplete, the objects appear aligned again.


Is there a known solution or workaround for this.

I.e. Is there are way to force TC to completely rebuild the object tree?


We're using TestComplete 7.52.



Thanks



Evan

6 Replies

  • I've noticed this as well, but it hasn't stopped me selecting the item I want. I usually use FindChild on the list/combobox, looking for an item with NativeUIAObject.Name equal to the string I'm looking for. Then I call AddToSelection on whatever object is returned. If I have to scroll the list, I refresh it afterwards and call FindChild again. It's always worked for me.
  • autopunk2007's avatar
    autopunk2007
    Occasional Contributor
    Thanks for your reply Tony,



    I do exactly what you've mentioned. Once the hierachy becomes jumbled, it remains jumbled no matter what you do.

    I can even reproduce this my manually scrolling up and down the list box.



    If I only needed to select an item, and not revisit the listbox, this would be fine. But when I revist the listbox, I can't select the item i need to.



    I'm hoping that AQA can resolve this asap.



    Thanks



    Evan
  • You do exactly the same thing? From your first post it looked like you were looking for the TextBlock containing the string you wanted and calling AddToSelection on its parent. If the tree has been rearranged, the Parent property might not be reliable. My method is to ignore the TextBlock in favor of the "NativeUIAObject.Name" property of the ListBoxItem itself. That way, the object returned by the search is the same one you call AddToSelection on, and you don't have to rely on the Parent being correct and up to date. That method should always work, regardless of how "jumbled" the tree has become.



    I'm not sure what you mean by revisting the listbox, but you should always search for the item you want, rather than trying to reuse a reference to the item from an earlier part of the test. Silverlight is free to reorganize and reuse the objects within list and combo boxes, so you can rarely assume that an old ListBoxItem reference is still good.
  • autopunk2007's avatar
    autopunk2007
    Occasional Contributor
    Our List Items contain several/multiple TextBlocks. We need to identify an list box item, by its the name/content of it'sTextBlock.(it's child object)



    By revisiting, I mean going back to the list box and trying to select another item.

    I don't use any existing references.



    The mixing up of the object hierachy is clearly a TestComplete issue.

    This is proven since after completely shutting down and restarting TestComplete, the hierachy is correct.



    The problem does not allow me to verify that an item is selected in a listbox because I can only recognise an item by its child (a textblock) and it's parent is incorrect.



    Evan
  • Ah, multiple TextBlocks in each item, so the NativeUIAObject.Name is probably just a class name that's the same for all items, right? Tricky.

    I agree that TC does have problems with Silverlight objects, and it certainly needs work, but I've found that it's not always as bad as it appears. It seems to me that the real problem lies with the Object Browser panel. The tree that you see in the Object Browser does often get badly out of sync with what's really on screen, and that seems to interfere with scripts. But in general I have found that there are no problems while actually running scripts that deal with the same objects, as long as I haven't used the Object Browser beforehand. That means that I often have to restart TC or go through various other rituals in order to get a script written, but once it's written it works OK at runtime. Very annoying, yes, but manageable.



    There may be another workaround for your situation. I assume that you are searching for the desired TextBlock by calling FindChild from the ListBox object, is that right? Instead of that, you may be better off if you first use FindAllChildren to find all the visible ListBoxItems, and from each of those call FindChild to find the TextBlock within and see if it's the one you're looking for. If it is, you already have what should be a valid and correct reference to its parent. If you get through the whole set of visible ListBoxItems without finding the item you want, then scroll a bit, refresh, and try it all again.
  • autopunk2007's avatar
    autopunk2007
    Occasional Contributor
    You're right Tony. Very tricky.

    I do agree that AQA can improve their support for silverlight, and I hope that this thread can help them improve this.



    After hours of painful attempts to find I decent/elegant workaround. I found something that can probably help you too.

    If you make any changes to TC options, the object browser regenerates.

    So, if you execute the following in your test for example, the object hierachy is completely rebuilt and it will fix itself.

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <meta content="Word.Document" name="ProgId" />
    <meta content="Microsoft Word 12" name="Generator" />
    <meta content="Microsoft Word 12" name="Originator" />





     
    Options.Web.TreeModel = "DOM"


    Options.Web.TreeModel = "Tree" 



     
    Sys.Refresh 


    I know, a strage workaround, but it works  (keeps the relationship between a textblock and ListBoxItem in sync.)


    This will suffice for what I need. But I hope it can help you and others until AQA resolve the problem.


    Thanks again Tony


    Evan