Forum Discussion

prashant_sankle's avatar
prashant_sankle
New Contributor
13 years ago

Unable to recognise object in .net application

Hi,



I'm testing .net application. On a particluar screen which is recognised as Infragistics.Win.UltraWinListBar.UltraListBar., I have to click on object with name e.g. Private. see attached screen shot). I have to recognise a object individually but Test completes recognised it as one object.PFA screen of the window.There is no option of clicking particular item.Is there any way to click particular item ?



Thanks,

Prashant



  • Hi Prashant,





    Items of an UltraListBar control are ownerdrawn and do not have separate UI objects that can be used to represent them in the object hierarchy. However, it is possible to work with them using the native methods and properties of the UltraListBar control which are available due to TestComplete's Open Applications feature. Here is a sample demonstrating how you can work with this control in script:

    function Test()

    {

      // The script works with the '<Infragistics>\NetAdvantage for .NET <version>\Samples\Win\WinListBar\CS\

      // Appearances CS\bin\Appearances.exe' sample application

      var groupName = "Group Two";

      var itemName = "Item Two";



      var ultraListBar = Sys.Process("Appearances").WinFormsObject("Form1").WinFormsObject("ultraListBar1");



      var group = FindGroupByName(ultraListBar, groupName);

      if (null == group) {

        Log.Error("Group was not found");

        return;

      }



      var item = FindItemByName(group, itemName);

      if (item == null) {

        Log.Error("Item was not found");

        return;

      }



      // Click the item 

      group.Selected = true;

      item.EnsureVisible();

      var rect = group.UIElement.ClipRect;

      ultraListBar.Focus(); 

      ultraListBar.Click(rect.Left + ocrObj.FoundLeft + 5, rect.Top + ocrObj.FoundTop + 5);

    }



    function FindGroupByName(ultraListBar, groupName)

    {

      for(var i = 0; i < ultraListBar.Groups.Count; i++)

        if (ultraListBar.Groups.Item(i).Text == groupName)

          return ultraListBar.Groups.Item(i);

      return null;

    }



    function FindItemByName(group, itemName)

    {

      var i;



      for(i = 0; i < group.Items.Count; i++)

        if (group.Items.Item(i).Text == itemName)

          return group.Items.Item(i);

      return null;

    }




    BTW, you can vote for your control in TestComplete Feature Survey.







  • Hi David,

    I have a similar issue. I am not getting the below statements 



     group.Selected = true;

      item.EnsureVisible();

      var rect = group.UIElement.ClipRect;

      ultraListBar.Focus(); 

      ultraListBar.Click(rect.Left + ocrObj.FoundLeft + 5, rect.Top + ocrObj.FoundTop + 5);



    Can you please explain the above to me?

    the item object which you are getting, is not being used anywhere. also ocrObj is not defined.



    Thanks

    Saket

  • Hi Saket,



    Here is the correct script. Please let me know how it works for you:

    function Test()

    {

      // The script works with the '<Infragistics>\NetAdvantage for .NET <version>\Samples\Win\WinListBar\CS\

      // Appearances CS\bin\Appearances.exe' sample application

      var groupName = "Group Two";

      var itemName = "Item Two";



      var ultraListBar = Sys.Process("Appearances").WinFormsObject("Form1").WinFormsObject("ultraListBar1");



      var group = FindGroupByName(ultraListBar, groupName);

      if (null == group) {

        Log.Error("Group was not found");

        return;

      }



      var item = FindItemByName(group, itemName);

      if (item == null) {

        Log.Error("Item was not found");

        return;

      }



      // Click the item 

      group.Selected = true;

      item.EnsureVisible();

      var groupRect = group.UIElement.ClipRect; 

      var itemRect = item.GetUIElement().Rect;

      var x = groupRect.Left + itemRect.Left + itemRect.Width / 2;

      var y = groupRect.Top + itemRect.Top + itemRect.Height / 2;

      ultraListBar.Click(x, y);

    }



    function FindGroupByName(ultraListBar, groupName)

    {

      var i;



      for(i = 0; i < ultraListBar.Groups.Count; i++)

        if (ultraListBar.Groups.Item(i).Text == groupName)

          return ultraListBar.Groups.Item(i);

      return null;

    }



    function FindItemByName(group, itemName)

    {

      var i;



      for(i = 0; i < group.Items.Count; i++)

        if (group.Items.Item(i).Text == itemName)

          return group.Items.Item(i);

      return null;

    }




    David