Forum Discussion

raj360logica's avatar
raj360logica
Occasional Contributor
8 years ago

Not able to get the text of an HTML element.

Hi Guys, 

I am working on a POC of my project using test complete. But I am unable to get the text of HTML element i.e. Button, Link etc. I am using Jscript.

 

I have to do it soon as possible.

 

Any help will be appropriated. 

 

Thanks..!

  • Usually, for HTML objects/components, this can be found using either the contentText or innerText property of the object.  Have you tried those?

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Usually, for HTML objects/components, this can be found using either the contentText or innerText property of the object.  Have you tried those?

    • raj360logica's avatar
      raj360logica
      Occasional Contributor

       

      obj.text and obj.innerText works for me.

       

      Thanks a lot. 

      • ishan_07's avatar
        ishan_07
        Occasional Contributor

        Hello,

        According to me, you should try following code.

        <script>
        function get_content() {
             var html = document.getElementById("txt").innerHTML;
             document.getElementById("txt").innerHTML = html.replace(/<[^>]*>/g, "");
        }
        </script>

        <body>
        <button type="submit" onclick="get_content()">Get Content</button>
        </body>