Page 1 of 1

Capture innertext from unknown number of tags

Posted: Tue Jan 14, 2014 4:21 pm
by basv
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

Re: Capture innertext from unknown number of tags

Posted: Wed Jan 15, 2014 10:11 am
by Swisside
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

Re: Capture innertext from unknown number of tags

Posted: Tue Jan 28, 2014 7:04 am
by brianafields
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").