Forum Discussion

ductreho's avatar
ductreho
Occasional Contributor
8 years ago
Solved

Unable to load property of a component

Hello,

 

I have a problem in my dektop application, I would like to retrieve the value of a textBox. This value is contained in an object belonging to the texBox.

My component has a formatedtext property that is an object with the following properties inside.

 

 

When I try to retrieve the value via the TC Code, it returns empty, as soon as I put a breakpoint at the object and I evaluate the value of the object myself, Value of the component is found. ( oComponent.FormattedText.OleValue)

 

The code used worked very well on TC 9 is that it no longer works since I passed under TC 12.

 

The fact of evaluating the value of this object then allows that I can recover it by letting the code go to the end. I also try to put a delay or make a resfresh of my component but nothing changes, how then do I do?

  • I based myself on the text property that works well to get around the problem, but I wanted to understand why the formatedtext does not work. In the end the focus of the component already present at the time of the search for the component block this update. Thank you

10 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Could you post the code that you're using?  What you described should be pretty straight forward.

    • ductreho's avatar
      ductreho
      Occasional Contributor

       

      The code is quite simple, and by deepening the simple fact of inserting a dialog by writing the search value allows me to find it, as when I evaluated it but without it the code does not work

       

      function GetTextWPF(oComponent)
      {

      //BuiltIn.ShowMessage(aqString.Trim(oComponent.FormattedText.OleValue,aqString.stAll));
      // BuiltIn.ShowMessage(aqString.Trim(oComponent.FormattedText.OleValue,aqString.stAll));
      if(typeof oRet=='object')
      return aqString.Trim(oComponent.FormattedText.OleValue,aqString.stAll);
      else
      return aqString.Trim(oComponent.FormattedText,aqString.stAll);
      }

      • shankar_r's avatar
        shankar_r
        Community Hero

        oRet is not defined anywhere in the function does it a global variable or oComponent?

         

        if(typeof oRet=='object')

         

        Also have you tried like below,

         

        function GetTextWPF(oComponent)
        {
        
        if(oComponent.Exists)
               return oComponent.wText;
              (or)
              return oComponent.getString();
              (or)
              return oComponent.getText();
              (or)
              return oComponent.AWTComponentName;
              (or)
              return oComponent.AWTComponentAccessibleName;
        else
              Log.Error("Object not exists");
              return "";
        }
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    ductreho wrote:

    My component has a formatedtext property that is an object with the following properties inside.

    When I try to retrieve the value via the TC Code, it returns empty, as soon as I put a breakpoint at the object and I evaluate the value of the object myself, Value of the component is found. ( oComponent.FormattedText.OleValue)

    ...

    The fact of evaluating the value of this object then allows that I can recover it by letting the code go to the end. I also try to put a delay or make a resfresh of my component but nothing changes, how then do I do?


    It's hard to say without seeing your tested app. It sounds like the FormattedText property is only initialized after a certain event occurs in the app, for example, when the object gets an input focus, or when some other property is being read. You need to find out what that event is (ask your developers) and add the corresponding action to your test.

     


    ductreho wrote:

     

    function GetTextWPF(oComponent)
    {
    var oRet="";
    oRet=oComponent.FormattedText;

    //BuiltIn.ShowMessage(aqString.Trim(oComponent.FormattedText.OleValue,aqString.stAll));
    //oComponent.Refresh()

    // BuiltIn.ShowMessage(aqString.Trim(oComponent.FormattedText.OleValue,aqString.stAll));
    if(typeof oRet=='object')
    return aqString.Trim(oComponent.FormattedText.OleValue,aqString.stAll);
    else
    return aqString.Trim(oComponent.FormattedText,aqString.stAll);
    }


    FYI, all native .NET strings have the .OleValue property, so using oComponent.FormattedText.OleValue should be enough. Make sure you are accessing the property of the correct component. Alternatively, check if your object or one of its child objects has the WPFControlText property - it's an extra property added by TestComplete to objects that contain text, such as TextBlock, Section, Paragraph and others.

     

    Maybe try something like this instead?

     

    function GetTextWPF(oComponent) {
      var text = "";
    
      if (aqObject.IsSupported(oComponent, "WPFControlText"))
        text = oComponent.WPFControlText;
      else if (aqObject.IsSupported(oComponent, "FormattedText"))
        text = oComponent.FormattedText.OleValue;
      else if (aqObject.IsSupported(oComponent, "Text"))
        text = oComponent.Text.OleValue;
      
      text = aqString.Trim(text, aqString.stAll);
      return text;
    }

     

     

    • ductreho's avatar
      ductreho
      Occasional Contributor

      I based myself on the text property that works well to get around the problem, but I wanted to understand why the formatedtext does not work. In the end the focus of the component already present at the time of the search for the component block this update. Thank you

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    1) Did you tried with textBoxObject.getString() or getText()?

    2) Did you tried with wText which is in-build of Test Complete?

    • ductreho's avatar
      ductreho
      Occasional Contributor

       

      I'm able to access the value of my component using the Text property, but I'd like to understand why I can not recover the value otherwise because I need to use the formatedText property for other constraint.