You can get the frame using Document.Window.Frames[] , which accepts the identifier (string) or index (int) of the frame.
You should also consider that you should wait until the DocumentCompleted event, and then do your job. If there is some iframe on the page, the DocumentCompleted event fires more than once and, using the code below, checking the eventarg URL, we are sure that this is the DocumentCompleted event of the main page that we need, then you can enable the flag to confirm that the document completed, and here or somewhere else, find the frame and the desired item.
Where is the code:
public partial class Form1 : Form { private void Form1_Load(object sender, EventArgs e) { this.webBrowser1.Navigate(@"d:\test.html"); this.webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; } bool completed = false; void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url == webBrowser1.Document.Url) { completed = true; } } private void clickToolStripButton_Click(object sender, EventArgs e) { if(completed) { var frame = webBrowser1.Document.Window.Frames["iframeid"]; var button = frame.Document.GetElementById("buttonid"); button.InvokeMember("click"); } } }
The contents of test.html:
<html> <head> <title>OUTER</title> </head> <body> Some Content <br/> Some Content <br/> Some Content <br/> iframe: <iframe src="test2.html" id="iframeid"></iframe> </body> </html>
The contents of test2.html:
<html> <head> <title>IFRAME</title> </head> <body> <button id="buttonid" onclick="alert('Clicked')">Click Me</button> </body> </html>
Screenshot:

source share