Forum Discussion

KB1's avatar
KB1
Champion Level 2
3 years ago

Finding object with text

Hello Smartbear community,

I'm still struggling with objects with the same ID and don't want to place them into an array because sometimes the position of that object differ.
So I thought maybe there is something like a findObject. I found it on the documention. (https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/find-method.html)
But how do I implement this in my test. E.G 

I want to find both of these through a variable that I already have mapped in the variables. is that possible?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I suggest you create a new function and use the Find method, to practice how Find works. Change the parameters and see what it does. There's also a FindAll method too. 

     

    Example,

     

    function FindTest()
    {
        var item = Aliases.TreeItem.Find("contentText", "Keywords", 5);
        if (item.Exists)
            Log.Message("The object was found.");
        else
            Log.Error("The object was not found.");
    }

     

     

    • KB1's avatar
      KB1
      Champion Level 2

      What do I need to fill in as keyword?

       

      • rraghvani's avatar
        rraghvani
        Champion Level 3

        Keyword? Sorry, I don't fully understand your question?

  • KB1's avatar
    KB1
    Champion Level 2

    the 1st line in the function it says ("Content Text", "Keywords", 5")

    What I did was change the content text to my variable that I have. but what do I have to fill in the keywords part?

    var item = Aliases.TreeItem.Find(+ Project.variables.Name + " (Default)", "Keywords", 5);

     Second question about this is. does it need the full namemapping path to to the treeitem.find? 

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The code

     

    Aliases.TreeItem.Find("contentText", "Keywords", 5);

     

    Finds the item that matches the property, where contentText = Keywords (can be "Application", "Groups", "Users", "Test User 7 (Test user)")

    If you read Find Method, it explains what each of the parameters do.

     

    Play around with these parameters of Find method. If the object is found, then it will highlight this.

     

    function Test()
    {
        var item = Aliases.TreeItem.Find("contentText", "Keywords", 5);
        if (item.Exists)
            Sys.HighlightObject(item);
    }

     

     

    See Add Aliases.