views:

573

answers:

2

WatIn provides great functionality for programmatic access to the displayed parts of a Web page.

I want to access the head part of the page, spedifically the META tags. Watin allows me access to the TITLE, but AFAICT nothing else. There is an InternetExplorer property which allows access to ShDocVw.InternetExplorer. I suspect this might be the start of the path. Even if it is the right path, I don't know how to follow it.

A: 
browser
    .Element(Find.ByName(nameAttribute))
    .GetAttributeValue("content");
eglasius
Thanks - this got me to ie.Element(Find.ByName("KEYWORDS")).GetAttributeValue("content"); I also found success with ie.Elements.Where(el => el.Id == "MetaKeywords")
RichardHowells
y, if you also have the id set to MetaKeywords (as your second way points reflects) you could just: ie.Element("MetaKeywords") :)
eglasius
+1  A: 

Hi Richard,

This will give you a collection of meta tags in your page.

Syntax in WatiN 2.0 beta 1:

var metaTags = browser.ElementsWithTag("meta");

Syntax in WatiN 2.0 CTPs and earlier:

var metaTags  = browser.Elements.Filter(Find.By("tagName", "META"));

If you prever the following syntax, read my blog post about adding elements to WatiN:

var metaTags = browser.ElementsOfType<Meta>();
Jeroen van Menen
Hi - I could not get this to compile on my WatiN install (1.3.0) - Elements is just a property for me.
RichardHowells
Sorry, I have corrected the example
Jeroen van Menen