Question

Normally I can access html tags and I can set their values via the code something like;

HtmlElementCollection coll = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement curElement in coll)
{
  if (curElement.GetAttribute("name").ToString() == "login")
  {
    curElement.SetAttribute("Value", "123456789"); 
  }
}

But if html input area exist in a iframe tag, This code didnt work,

And I changed line:

var coll = webBrowser1.Document.GetElementsByTagName("input");

to

var coll = webBrowser1.Document.Window.Frames[0].Document.GetElementsByTagName("iframe")

But it still didnt work. Please Help. I cannot get over this problem since last week

Was it helpful?

Solution

Your code looks like it should work if you change this line:

coll = webBrowser1.Document.Window.Frames[0].Document.GetElementsByTagName("iframe")

to

coll = webBrowser1.Document.Window.Frames[0].Document.GetElementsByTagName("input");

Here is a working example...

HtmlWindow iframe = webBrowser1.Document.Window.Frames[0];
HtmlElement input = iframe.Document.GetElementsByTagName("input")[0];

input.SetAttribute("value", "Test");

This assumes obviously that you only have at least one iframe element and at least one input element in the child document.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top