Reputation: 51
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.
Upvotes: 1
Views: 3665
Reputation: 454
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!";
}
}
Upvotes: 1