martin.malek
martin.malek

Reputation: 2218

How to get Dom tree in GeckoFX

I started to play with GeckoFX. Unfortunately I didn't found any big documentation for that. I need to get DOM tree for the page. Iterate every element and get it's information. Can someone please help me?

Upvotes: 2

Views: 5527

Answers (4)

SuperBisco
SuperBisco

Reputation: 31

If you want to use XPath, you can try with this:

 browser.LoadXml("<MyTag><div>helloworld</div></MyTag>");

 var r = browser.Document.EvaluateXPath("//div");
 Assert.AreEqual(1, r.GetNodes().Count());

so in prev code:

GeckoElementCollection nodes = browser.Document.EvaluateXPath("//div").GetNodes();    
foreach(GeckoNode node in nodes)
{
    //do whatever you need to do with the node .. 
    GeckoElement element = node as GeckoElement;
    //..
}

Upvotes: 0

Scott
Scott

Reputation: 306

I know this is an older question but someone may still be looking for an answer.

GeckoNodeCollection nodes = geckoWebBrowser1.Document.GetElementsByName("*");
foreach(GeckoNode node in nodes)
{
    //do whatever you need to do with the node .. 
    GeckoElement element = node as GeckoElement;
    //..
}

Upvotes: 6

Sire
Sire

Reputation: 4358

Example code:

GeckoElementCollection links = geckoWebBrowser1.Document.GetElementsByTagName("a");
foreach (GeckoElement link in links) {
    Debug.WriteLine(link.GetAttribute("href"));
}

Upvotes: 3

Priyank Bolia
Priyank Bolia

Reputation: 14441

nsIDOMNode will provide you the DOM traversing ability. You can start from the Document node. You can look into the nsInterfaces.cs file for the interface details.

Upvotes: 0

Related Questions