Why can't you access the button by its id?
Its a childElement of the logbox. so i have to use a loop trough the logbox element.
By that logic EVERYTHING is a "child" of the <html> root element and you couldn't access anything by it's id. (?)
please post the html code for the <form>. Erase any parts we don't need to see (hardcoded styling, etc).
something very similar to
Code:
<form id="logbox" method="post">
...
<input type=submit value="Start new chat" />
</form>
so we can see the names and IDs of the controls, and their layout.
I haven't used these classes/functions in a while so I made up a demo to test...maybe it helps give you ideas..
http://tinypic.com/r/20zvcr8/8
text copy of vb.net code above, 99.9% the same as c# (in this example)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("C:/Users/Buckau/Desktop/index.html")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim _entirePage As HtmlDocument = WebBrowser1.Document
''Find the login <form>
Dim _logBox As HtmlElement = _entirePage.GetElementById("logbox")
If _logBox Is Nothing Then
MsgBox("Log box not found!")
Exit Sub
End If
''We found it
MsgBox("_logBox.InnerText: " & Environment.NewLine & _logBox.InnerText _
& Environment.NewLine & Environment.NewLine _
& "_logBox.InnerHtml: " & Environment.NewLine & _logBox.InnerHtml)
If _logBox.Children.Count > 0 Then
''Loop over it's children
Dim _tmpStr As String = ""
For Each xx As HtmlElement In _logBox.Children
_tmpStr = xx.GetAttribute("value")
If String.IsNullOrEmpty(_tmpStr) Then
MsgBox("input doesn't have a 'value' item" & Environment.NewLine _
& "name: " & xx.Name)
Else
MsgBox("name: " & xx.Name & Environment.NewLine _
& "value = " & _tmpStr)
End If
Next
Else
MsgBox("The _logBox has No Children Elements! ie. an empty <form></form>.")
End If
MsgBox("Done analyzing") ''
End Sub
The test html file I practiced on:
Code:
<html>
<head>
<title>yunoTest</title>
</head>
<body>
<form id="logbox" method="post">
<input type="text" name="email" value="youremail@mail.com" /><br />
<input type="password" name="password" value="********" /><br />
<input type=submit value="Start new chat" />
</form>
</body>
</html>
tip: Use HtmlElement instead of HtmlInputElement (unless you KNOW all your items will be <input> elements). GetAttribute() is useful..but make sure it returns something other than empty string.
Find the logbox form based on it's ID, then loop over its children, looking for one who has a defined attribute named 'value', with the value "Start new Chat": this is your button.
Look forward to your reply.