Forum Discussion

szein's avatar
szein
Occasional Contributor
13 years ago

Cannot access onscreen objects in Silverlight 4

hello,

I downloaded TestComplate 8.5 tial edition, and currently testing how to automate silverlight tests.

when i record the test, it does not run again successfully. it breaks when it tries to find onscreen objects!



i donno if i am missing something but here is what i did:


  • i made sure that the IE is using latest silverlight version

  • i made the xap file open using the tcagPacher utility, and copies it back on web server

  • i clear the cache before start testing


i even tried to write my own test script:

//suppose that pg is the page that has silverlight object

// the whole silverlight app under test is a simple page with 2 buttons!

var item = pg.Find("idstr", "silverlightControlHost", 10);



var obj = item.SlObject("btnName");  // <==it breaks here, cannot find object!



Help Please!



thanks,

Samer

3 Replies

  • szein's avatar
    szein
    Occasional Contributor
    hello,



    seems that now it works (but i am sure there is better solution)



    it seems that i need to go and catch element as in tree in object browser (Hierarchal)



    var item = pg.Find("idstr", "silverlightControlHost", 10);

    //catch object 0

    item = item.Object(0);

    // then catch the main page:

    item = item.SlObject("MainPage", "", 0);

    //then catch the button (the button is direct child for main page)

    item = item.SlObject("btnName"); 



    item.Click();



    However, this is not practical at all!!

    i need to access the objects directly, how?



    thanks!

    Samer


  • Anonymous's avatar
    Anonymous

    Hi Samer,





    Try this code:



    function Test()

    {

      // ...  Obtain the pg object

      var silverlightControl = pg.Find("idstr", "silverlightControlHost", 10);

      var button = silverlightControl.Find(new Array("SlClassName", "NativeSlObject.Name.OleValue"), new Array("Button", "btnName"), 10);

      if (button.Exists)

        button.Click();     

    }

  • szein's avatar
    szein
    Occasional Contributor
    thanks Tanya, you really made my day!



    Samer