MetaTag class question

Class library usage, coding and language questions.
staceyb
Posts: 5
Joined: Fri Sep 27, 2013 9:23 pm

MetaTag class question

Post by staceyb » Fri Sep 27, 2013 9:36 pm

Hi,

I am trying to programmatically get all the meta tags in the head portion of a page. I have tried the below code
and the list comes as empty despite there being 2 meta tags in the head section.

<head>
<meta charset="utf-8">
<meta name="robots" content="NOODP,NOYDIR">
</head>

repo headsection rxpath
/dom/head
Ranorex.HeadTag headTag = repo.DOM.headsection;
			
IList<Ranorex.MetaTag> metaTags = headTag.FindChildren<Ranorex.MetaTag>();
            
foreach (Ranorex.MetaTag metaTag in metaTags)
{								
				
	Report.Info(metaTag.Name);
				
}
I can on the other hand obtain an adapter to the first metatag using a repo item with rxpath head/meta[1]

Why is the IList empty in the code example?

I am looking many pages and do not know how many and which meta tags I will find on each page so would prefer to obtain the meta tags dynamically on each page.

Your help is appreciated.

Thanks,
Stacey

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

Re: MetaTag class question

Post by Support Team » Mon Sep 30, 2013 5:16 pm

Hello,

You would get a list back if you enter '/dom/head' in Spy not a single object.
If you want to get all MetaTags in all dom objects, you could use:
IList<Ranorex.HeadTag> headTags = Host.Local.Find<Ranorex.HeadTag>("/dom/head");			
foreach (Ranorex.HeadTag headTag in headTags)
{
	IList<Ranorex.MetaTag> metaTags = headTag.FindChildren<Ranorex.MetaTag>();				
	foreach (Ranorex.MetaTag metaTag in metaTags)
	{				
		Report.Info(metaTag.Name);					
	}			
}
Another way would be to specify your dom object:
Ranorex.HeadTag headTag = "/dom[@domain='www.w3schools.com']/head";
Regards,
Markus (T)

staceyb
Posts: 5
Joined: Fri Sep 27, 2013 9:23 pm

Re: MetaTag class question

Post by staceyb » Tue Oct 01, 2013 12:29 am

Thanks Markus, very helpful.

I am specifying the domain in the Host.Local.Find path string as the domain has to be dynamic too and am getting back the metastring for the appropriate domain and window.

Thanks for your help,
Stacey