How to get nsIDOMHTMLDocument in GeckoFx?

144 views Asked by At

I'm trying to get list of elements in DOM:

private void geckoWebBrowser1_DocumentCompletedEvent(object sender, EventArgs e) {

   nsIDOMHTMLDocument givenDocument = geckoWebBrowser1.Document as nsIDOMHTMLDocument;
   var iframes = givenDocument.GetElementsByTagName(tagname);
   var iframe = iframes.Item(0);

}

but givenDocument is always null.

I'm trying to find how to work with any of nsIDOMHTML types. Everything I've tried returned null so far.

1

There are 1 answers

0
Bartosz On BEST ANSWER

Why do you cast to nsIDOMHTMLDocument?

You can get the .GetElementsByTagName(tagName); method from GeckoDocument as well, and this works OK without the cast.

  GeckoDocument document = this.Browser.Document;
        GeckoFrameElement frame = document.GetElementsByTagName("frame")[0] as GeckoFrameElement;