How to get a Dom tree in GeckoFX
I started playing with GeckoFX. Unfortunately I haven't found much documentation for this. I need to get the DOM tree for a page. Iterate over each element and get its information. Can someone please help me?
+2
martin.malek
source
to share
4 answers
Sample code:
GeckoElementCollection links = geckoWebBrowser1.Document.GetElementsByTagName("a");
foreach (GeckoElement link in links) {
Debug.WriteLine(link.GetAttribute("href"));
}
+3
Sire
source
to share
I know this is an old question, but someone might still find the 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;
//..
}
+5
Scott
source
to share
nsIDOMNode
will give you the ability to traverse the DOM. You can start from the node. You can view the file nsInterfaces.cs
for interface details.
0
Priyank bolia
source
to share
If you want to use XPath, you can try:
browser.LoadXml("<MyTag><div>helloworld</div></MyTag>");
var r = browser.Document.EvaluateXPath("//div");
Assert.AreEqual(1, r.GetNodes().Count());
so in the 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;
//..
}
0
SuperBisco
source
to share