Forum Discussion

mgroen's avatar
mgroen
Frequent Contributor
14 years ago

Get and "translate" the value of an object property (of type: Innertext)

Hi,



working on a project now, I need some assistance.



What I do is, create a new file in our web application. This file is identified by a number (generated by the system itself). I want to re-use this number , in another script, to edit this file. Therefore, I need to save the filenumber (generated by the system) into a variable, so I can call the file with the variable.



The filenumber (in this example) is: 440020498



In the object spyder it can be retrieved by the "Innertext" property (see attached screenshot).



The point is I cannot seem to get this number to put it in a variabele. Probably, because (I think) it is an object and not a number (not sure if this is the cause).



Is there any good approach? By the way I am using keyword tests (in combination with some code snippets)



Please advice in this exercise.


  • karkadil's avatar
    karkadil
    Valued Contributor
    innerText should be a text, not an object. Probably you have to delete leading spaces from the text.



    What exactly do you mean by "I cannot seem to get this number to put it in a variabele"? Do you get error message or...?
  • mgroen's avatar
    mgroen
    Frequent Contributor


    innerText should be a text, not an object. Probably you have to delete leading spaces from the text.



    What exactly do you mean by "I cannot seem to get this number to put it in a variabele"? Do you get error message or...?    





    hi,

    I need to capture the innertext value (which contains the number of created file), put this in a variabele , so I can re-use this "string of numbers" in another script.



    What I mean is, I used the Object Spyder and selected "On Screen Object" to select the object which contains the filenumber itself. That is why I use the term "Object". I created a variable of type Object , and used a "Set Variable Value" statement to put the filenumer in this variable.

    Also I created a log message in which I post the variabele. But this log entry remains empty. That's why I think this approach does not work. (later on, when I have succeeded to capture this value to a variable, I want to use this variable in a "set text" statement to enter the filenumber in another script).



    See attached screenshot for the statement I used.

    Hope this makes my challenge more clear - If any questions please don't hesitate to ask for clearification.















  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You should not log a message using the object.  I would change your SetVariable to point to the object's innerText property instead or Log Message for the object.innerText.



    Logging the object will result in a blank because the object is not a string...
  • mgroen's avatar
    mgroen
    Frequent Contributor


    You should not log a message using the object.  I would change your SetVariable to point to the object's innerText property instead or Log Message for the object.innerText.



    Logging the object will result in a blank because the object is not a string...    





    Hi,

    thanks for my delayed reply.



    I am beginning to understand your suggested approach (I think), however, I'm not sure.

    What's the best way to do set the variable to an Innertext value? I guess I have to use a Code snippet? What would then be the code to use (dont have much experience with scripting so my knowlegde is very basic on that aspect)



    Please advice.



  • mgroen's avatar
    mgroen
    Frequent Contributor
    Extra information to my previous comment:



    what I just tried:

    created an variable 'dossier' of type string (on project level);



    in my keyword test,

    I inserted a SetVariable command, and I chose (Onscreen object), then I used the spyder to find/select the object.

    In this example the object's full path is:



    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.cellWfeWfeInputcolorWfeInputread.panel310021229



    the thing I need to catch here is in fact the "dossiernummer", which is last part of the object's path (in this example i.t's 310021229).



    I also created a log message to try to post the variable to the log, to see if it succeeded.



    However, it's not working.

    I get a "type message" when I run this test :(



    I think it's failing because there is mismatch on the variable's type (string), compared to the onscreen object which contains the filenumber. Point is that I do know of what type of object this is (it's not a string, that's for sure).



    What I do know is, if I use the Object spider, to navigate to the field which contains the 'dossiernumber', I see the 'Innertext" property contains the 'dossiernumber', but I don't know how to catch that "string of numbers", and put it in a variable....



    Here is what the Object Spyder tells me of this object:



    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.Cell(1, 4).Panel(0).innerText



    So, the big questions are:



    1) what kind of variable to use?

    2) what piece of code to use to select the last 9 digits of the object's full path

    3) Put this all into one working script... :)



    Any tips or ideas are very much welcome!






  • Hello Mathijs,





    The panel310021229 object is an object that allows you to work with the corresponding Panel element of the tested web page. TestComplete used the value of the panel's innerText property to create the name of the panel310021229 object, but generally, this name does not change - it's a static name used in the Name Mapping tree of your TestComplete project.





    You need to obtain the contents of the panel through the object's innerText property. The property is a string, so you need to keep the property value within a variable of the String type. After you've created the variable of the String type, you can use the Set Variable Value operation to assign the value of the innerText property to the variable. In the first step of the Set Variable Value operation dialog, select the variable and click Next. In the "Set New Value" step, you can use either the Object Property mode, or the Code Expression mode. In both cases, you can specify one of the following values in the Value field:





    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.cellWfeWfeInputcolorWfeInputread.panel310021229.innerText





    or





    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.Cell(1, 4).Panel(0).innerText





    Does this help?
  • mgroen's avatar
    mgroen
    Frequent Contributor


    The panel310021229 object is an object that allows you to work with the corresponding Panel element of the tested web page. TestComplete used the value of the panel's innerText property to create the name of the panel310021229 object, but generally, this name does not change - it's a static name used in the Name Mapping tree of your TestComplete project.





    You need to obtain the contents of the panel through the object's innerText property. The property is a string, so you need to keep the property value within a variable of the String type. After you've created the variable of the String type, you can use the Set Variable Value operation to assign the value of the innerText property to the variable. In the first step of the Set Variable Value operation dialog, select the variable and click Next. In the "Set New Value" step, you can use either the Object Property mode, or the Code Expression mode. In both cases, you can specify one of the following values in the Value field:





    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.cellWfeWfeInputcolorWfeInputread.panel310021229.innerText





    or





    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.Cell(1, 4).Panel(0).innerText





    Does this help?    





    Hi,

    thanks for your tip.



    In fact, I have created an alternative way.

    What I have done is following:

    I have retrieved the value of innertext, by creating a variable "dossier" of type Object.

    See attached screenshot (1)



    After that, I used the Log message statement to see if the value is stored. I used the statement "ProjectSuite.Variables.dossier.innertext" , and it is actually being displayed in the log file, so this is good.



    However, I cannot acces this value (dossier.innertext) in other tests :( The variable dossier is of type "projectsuite".



    So, so far I have not used a variabel of type "string" , I will try this approach as well.







  • mgroen's avatar
    mgroen
    Frequent Contributor


    Hello Mathijs,





    The panel310021229 object is an object that allows you to work with the corresponding Panel element of the tested web page. TestComplete used the value of the panel's innerText property to create the name of the panel310021229 object, but generally, this name does not change - it's a static name used in the Name Mapping tree of your TestComplete project.





    You need to obtain the contents of the panel through the object's innerText property. The property is a string, so you need to keep the property value within a variable of the String type. After you've created the variable of the String type, you can use the Set Variable Value operation to assign the value of the innerText property to the variable. In the first step of the Set Variable Value operation dialog, select the variable and click Next. In the "Set New Value" step, you can use either the Object Property mode, or the Code Expression mode. In both cases, you can specify one of the following values in the Value field:





    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.cellWfeWfeInputcolorWfeInputread.panel310021229.innerText





    or





    Aliases.iexplore.pageApacheGeronimoEmbeddedTomcat.panelData2.panel.panelIcWindowbody.panelIcWindowcontents.panel.panelWfeContainer.panelWfeBody.panel.tableWfeWfeie.Cell(1, 4).Panel(0).innerText





    Does this help?    





    Hi Alex,

    in response to your question:

    I have tried your suggested method, and it worked! Thanks!



    One other question I have: I have succesfully captured the string and put it in a variable.



    However, the string contains some spaces before the actual numbers - is there a way to trim out these spaces?



    Thanks in advance.