Forum Discussion

abroadbent's avatar
abroadbent
New Contributor
11 years ago

extract text from web page and assign it to a variable

Hi there, I need to use TC to extract text from a web page control and store it in a variable, so that I can check for that same text elsewhere in the test. I don't know if this procedure has a name that I'm not familiar with yet, but I haven't found any threads or help on this topic. Thanks for any guidance.
  •   Most of my tests are written in VBScript so I may not be the best to answer this question for you, but let me give you some suggestions from my experience. Maybe that will get you going in the right direction. 



      I'll assume that if you can pull this information from the page (table cell) using Selenium that you know the tabel cell object that you're trying to pull from. 



      For Keyword tests try this:

    1. Bring up the page on the 'AUT' (Application Under Test).

    2. Select the 'Set Variable Value' from the 'Statements' operations.

    3. Select the variable that you want to save the value in and click 'Next'.

    4. Select 'Onscreen Object' and click on the '...' box on the right of the 'Value' text area.

    5. Select the table cell object using one of the ways in the 'Select Object' dialog. 



      That should get you down the road on Keyword tests. Now I'll give you an example of what I would do using VBScript.



    1. Start by setting the object varible to the table cell the value is in. This is an object that is in your Name Mapping. In VBScript you have to use Set to assign an object to a variable.

    Set objToGetValueFrom = Aliases.browser.page.panelContent.table.cell

    2. Assign the table cell value to a variable. In VBScript I use GetAttribute and then use the attribute name, in this example 'innerText', to tell it which attribute to get. This is where using your developer tools will help you to find the right attribute that you want to pull from the object. Other attributes could be 'outerText', 'isEnabled', 'bgColor', 'href', etc.

    strValue = objToGetValueFrom.GetAttribute("innerText", text)



      The strValue variable should now contain the value of the attribute innerText of the objToGetValueFrom object.



      Obviously if you're using another language for scripting this will look a little different, but I hope this gets you a little bit further down the road. Let me know if this doesn't make sense. 



    JC
  • aLostDawg's avatar
    aLostDawg
    Occasional Contributor
      Most of my tests are written in VBScript so I may not be the best to answer this question for you, but let me give you some suggestions from my experience. Maybe that will get you going in the right direction. 



      I'll assume that if you can pull this information from the page (table cell) using Selenium that you know the tabel cell object that you're trying to pull from. 



      For Keyword tests try this:

    1. Bring up the page on the 'AUT' (Application Under Test).

    2. Select the 'Set Variable Value' from the 'Statements' operations.

    3. Select the variable that you want to save the value in and click 'Next'.

    4. Select 'Onscreen Object' and click on the '...' box on the right of the 'Value' text area.

    5. Select the table cell object using one of the ways in the 'Select Object' dialog. 



      That should get you down the road on Keyword tests. Now I'll give you an example of what I would do using VBScript.



    1. Start by setting the object varible to the table cell the value is in. This is an object that is in your Name Mapping. In VBScript you have to use Set to assign an object to a variable.

    Set objToGetValueFrom = Aliases.browser.page.panelContent.table.cell

    2. Assign the table cell value to a variable. In VBScript I use GetAttribute and then use the attribute name, in this example 'innerText', to tell it which attribute to get. This is where using your developer tools will help you to find the right attribute that you want to pull from the object. Other attributes could be 'outerText', 'isEnabled', 'bgColor', 'href', etc.

    strValue = objToGetValueFrom.GetAttribute("innerText", text)



      The strValue variable should now contain the value of the attribute innerText of the objToGetValueFrom object.



      Obviously if you're using another language for scripting this will look a little different, but I hope this gets you a little bit further down the road. Let me know if this doesn't make sense. 



    JC
  • aLostDawg's avatar
    aLostDawg
    Occasional Contributor
    Could you give a few more details? Are you using Keyword tests, or a scripting language? If you're using a scripting language which one? 



    What sort of code base are you working with? 



    These all will affect how you extract text from a webpage. 



    You can check the attributes of the webpage element that you want text from if you use some sort of tool to inspect the webpage. For example IE has Developer Tools (F12).



    Let us know some more details and someone will get you some help. 
  • claventure's avatar
    claventure
    Occasional Contributor
    Thank you.  I am on day 4 of using TestComplete productively.  I was able to automate two test cases using the recorder, Object Browser, adding variables, and writing a small script to round to tenths.  It looks good so far.  Today I need to figure out how to get a handle on tree nodes (expand/collapse) that appear to be "hidden" and then, finally figure out how to run these tests "headless" automatically at the end of a build.  Fingers crossed, because when those two things are finished I can begin to build real framework to build large suites of tests.  The documentation, help facility, and forums like these have helped.  No blockers so far . . .
  • abroadbent's avatar
    abroadbent
    New Contributor
    Thanks for replying. Some background: I've been using Selenium on C# for my testing, but now I'm looking into using TestComplete, hopefully so that my peers can record their own tests without needing to know how to code, and also perhaps to speed up the test automation process. With Selenium, I'm able to pull an attribute from a web page (such as a number from a grid), then run a report and check for that same number, verifying that the report is running successfully.



    With TestComplete, I've been using Keyword tests for the most part, then converting to a script (C#) and making edits where needed. So if there is a way to store a value into a variable while recording a test, that would be ideal. Failing that, how can I do it in C#? I've been reading through pages and pages of help files, and I've made lots of guesses in the script, but my syntax is apparently wrong, and the error messages are no help.



    The more time I have to spend typing code, the less of a benefit it is to use TestComplete. That's why I'm looking for some way to point to a web control while recording a Keyword test, and store its text value into a variable that I can access later. I won't always be able to predict what these values are, so I can't paramaterize the values.



    I'm familiar with IE Dev Tools, FireBug, etc. but I need the test itself to extract that data while it is running.



    Thanks again
    • AutoAditya's avatar
      AutoAditya
      New Contributor

      How to find the visible text value using getattribute.It doesnot have any attribute

    • AutoAditya's avatar
      AutoAditya
      New Contributor

      How to work with visible text..using getattribute??

      It doesnot have any attribute value

  • claventure's avatar
    claventure
    Occasional Contributor
    I am very glad I just saw this post.  I have been working with Selenium, Java, and C# for automated testing (successfully) for some time.  Recently, I was introduced to TestComplete (two days ago).  I am hoping that this tool is as friendly and useful as what I am accustomed to.  This post is my question exactly.  Perhaps this should be a "How To" on the SmartBear Site because this is obviously a common need for any test developer.  Thanks.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Chris,


     


    First of all, welcome to the TestComplete Community :)


     


    To get started with TestComplete, you can use the Recording feature. It will record all your actions over your tested app that you can modify after analyzing. Please refer to the "Recording Tests" article for more information.


     

    • AutoAditya's avatar
      AutoAditya
      New Contributor

      How to find the value of visible text

       

      It does not have any property.....Kindly help


      TanyaYatskovska wrote:

      Hi Chris,


       


      First of all, welcome to the TestComplete Community :)


       


      To get started with TestComplete, you can use the Recording feature. It will record all your actions over your tested app that you can modify after analyzing. Please refer to the "Recording Tests" article for more information.