cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to get the text of an HTML element.

SOLVED
Occasional Contributor

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..!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Not able to get the text of an HTML element.

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
4 REPLIES 4
Community Hero

Re: Not able to get the text of an HTML element.

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


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Occasional Contributor

Re: Not able to get the text of an HTML element.

 

obj.text and obj.innerText works for me.

 

Thanks a lot. 

Occasional Contributor

Re: Not able to get the text of an HTML element.

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>

 

Community Hero

Re: Not able to get the text of an HTML element.

Hi,

 

This is not Selenium forum and TestComplete perfectly handles this via the mentioned .contentText property without any additional page code injecting.

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors