Capture innertext from unknown number of tags

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
basv
Posts: 3
Joined: Wed Dec 04, 2013 9:45 am

Capture innertext from unknown number of tags

Post by basv » Tue Jan 14, 2014 4:21 pm

Hello,

I'm pretty stuck with the following case. I need to get the innertext from all the <a>-tags from an unknown number of <a>-tags and put all these innertexts in a simple data table.

The following (variable) code is given, for instance:

Code: Select all

...
<body>
	<ul class="nav">
		<li class="btn">
		  <a href="1.htm">One</a>
		</li>
		<li class="btn">
		  <a href="2.htm">Two</a>
		</li>
		<li class="btn">
		  <a href="3.htm">Three</a>
		</li>
	</ul>
</body>
...
How can I do that, since I don't know how many <a>-tags are available? A simple 'Get Value' does not work, right?

Regards,
Bas

Swisside
Posts: 92
Joined: Thu Oct 10, 2013 10:40 am

Re: Capture innertext from unknown number of tags

Post by Swisside » Wed Jan 15, 2014 10:11 am

Hi !

You can try the following code which will return in this case : One, Two, Three.


You can then store those values wherever you want !

You need to adapt the first line so that it point to the UL element.
IList<LiTag> list = repo.TestliHtml.UlTagNav.FindChildren<LiTag>();
			
list.Count();
for (int i = 0; i <= list.Count-1 ; i++){
	LiTag tagtest = list;
			
	ATag atag = tagtest.FindChild<ATag>();
				
	string test = atag.InnerText;
				
	Report.Log(ReportLevel.Info,test);
				
}



Cheers
A simple thank you always does wonders !

brianafields
Posts: 1
Joined: Tue Jan 28, 2014 6:52 am

Re: Capture innertext from unknown number of tags

Post by brianafields » Tue Jan 28, 2014 7:04 am

basv wrote:Hello,

I'm pretty stuck with the following case. I need to get the innertext from all the <a>-tags from an unknown number of <a>-tags and put all these innertexts in a simple data table.

The following (variable) code is given, for instance:

Code: Select all

...
<body>
	<ul class="nav">
		<li class="btn">
		  <a href="1.htm">One</a>
		</li>
		<li class="btn">
		  <a href="2.htm">Two</a>
		</li>
		<li class="btn">
		  <a href="3.htm">Three</a>
		</li>
	</ul>
</body>
...
How can I do that, since I don't know how many <a>-tags are available? A simple 'Get Value' does not work, right?

Regards,
You have to replace the continuous use of unordered list and list items while coding but with only HTML this is not possible.To replace them you have to go for either Javascript or PHP.With javascript this is very easy just use textarea(with id "description").
click here for more information