1

This code access iframe and gets me source code.

string content = null;
var iframe = browser.Document.GetElementsByTagName("iframe").FirstOrDefault() as Gecko.DOM.GeckoIFrameElement;
if (iframe != null)
{
    var html = iframe.ContentDocument.DocumentElement as GeckoHtmlElement;
    if (html != null)
        content = html.OuterHtml;

    textBox1.Text = content;
}

I tried puting some code

string content = null;
var iframe = browser.Document.GetElementsByTagName("iframe").FirstOrDefault() as Gecko.DOM.GeckoIFrameElement;
if (iframe != null)
{
    var html = iframe.ContentDocument.DocumentElement as GeckoHtmlElement;
    if (html != null)
        content = html.OuterHtml;

    textBox1.Text = content;

    GeckoElementCollection elements = browser.Document.GetElementsByName("username");
    foreach (var element in elements)
    {
        GeckoInputElement input = (GeckoInputElement)element;
        input.Value = "Auto filled!";
    }
}

But it wont work as code dont find elements. Any ideas?

Tried searching google for any iframe examples but seems that there isnt any good documentation for it.

2
  • Check this answer stackoverflow.com/a/25854559/2224701 Commented Sep 21, 2014 at 16:05
  • I know selenium webdriver and I tried but I need to work with firefox browser (geckoFx) Commented Sep 21, 2014 at 17:18

1 Answer 1

1

Why are you looking for in the main document? You should look for in a frame.

string content = null;
var iframe = browser.Document.GetElementsByTagName("iframe").FirstOrDefault() as Gecko.DOM.GeckoIFrameElement;
if (iframe != null)
{
    var html = iframe.ContentDocument.DocumentElement as GeckoHtmlElement;
    if (html != null)
        content = html.OuterHtml;

    textBox1.Text = content;

    GeckoElementCollection elements = iframe.ContentDocument.GetElementsByName("username");
    foreach (var element in elements)
    {
        GeckoInputElement input = (GeckoInputElement)element;
        input.Value = "Auto filled!";
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, "browser.Document" is main document. "iframe.ContentDocument" iframe doc. Thanks for help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.