How to find child TAGs in DOM tree?

Class library usage, coding and language questions.
Zee357
Posts: 8
Joined: Tue Jan 05, 2016 7:43 pm

How to find child TAGs in DOM tree?

Post by Zee357 » Wed Jan 20, 2016 4:55 pm

I have Repo items in Web application that represent HTML tags that may or may not have children. I'll show examples below. I want to determine through script what the DOM tree is and manipulate it accordingly.

Here I want to see what sits beneath <>TD.

<>TBody
<>TR
<>TD

<>TBody
<>TR
<>TD
<>Big '20'
<>Br
<>Div ' Sold Out '
<>B '8:00 PM'
<>Br

<>TBody
<>TR
<>TD
<>Big '21'
<>Br
<>Div
<>B '8:00 PM'
<>A 'Tickets'
<>Br

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to find child TAGs in DOM tree?

Post by Support Team » Fri Jan 22, 2016 1:58 pm

Hi Zee357,

I’m unfortunately not exactly sure what you want to do, but you can iterate through the children of a Repository Item by using the following code snippet
TdTag item = repo.WebPage.Table.FindSingle(".//td[@innertext='Big 20']");
foreach(Unknown child in item.Children)
	Report.Info(child.ToString());
If you would like to get all descendants you can use this snippet
TdTag item = repo.WebPage.Table.FindSingle(".//td[@innertext='Big 20']");
IList<Unknown> descendants = item.FindDescendants<Unknown>();
foreach(Unknown child in descendants)
	Report.Info(child.ToString());
Please let me know if that helps solving your problem.

Regards,
Markus (S)