Forum Discussion

cmpenn's avatar
cmpenn
Contributor
7 years ago
Solved

Find and FindChild methods returning functions instead of objects

Working with a dev and unable to see why this keeps happening. We narrowed it down to the find method using the following:

 

 

this.GetComboBoxItemByText = function (text) {
        var thing = this.Popups.GetPopupByIndex(1)
            .WPFObject("PopupRoot", "", 1)
            .WPFObject("Decorator", "", 1)
            .WPFObject("NonLogicalAdornerDecorator", "*", 1);
        var thing2 = thing.FindChild("TextBlock", text, 2, true);
        return thing2;
    }


When looking at the local variables,

thing is an object

thing2 is a function

 

thing2 should be an object, and is failing when trying to click on it after this call.

  • My guess is that it's because 

    this.GetComboBoxItemByText 

     is assigned to what is returning as the function... but if the function failed, like due to improper parameters, it might just return as the function and not as the result of the function... just my best guess. 

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    How do you determine that it's a function?  I'm using FindChild in a LOT of my tests and it returns either the OnScreen object I'm looking for or a "stub" object with the Exists property set to False.  If you can show us how you determine it's a function, that would be bonus. 

     

    Additionally, after you attempt to find an object, you should always check the "Exists" property to see if it's true or false... if it's false, then you didn't actually find the object.

  • Figured out the issue...

     

    Had the wrong information in the parameter slot.

     

    I'm still confused on why that caused find to return as a function though.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      My guess is that it's because 

      this.GetComboBoxItemByText 

       is assigned to what is returning as the function... but if the function failed, like due to improper parameters, it might just return as the function and not as the result of the function... just my best guess.