VB2008

I am trying to click a button on a website but its not working for some reason. I've used this code on another site but the html code doesnt look the same.

Here's the HTML Code
<input type="submit" onclick="return fnbValidateLogin()" value="Login" name="Login">

Here's what i Tried

theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("value").Equals("Login") Then
curElement.InvokeMember("onclick")
End If
Next
End Sub

i tried a few combinations, but its not working. Please Help

Thank You

Seems that it is not your vb.net code, but your HTML.
Try it with this HTML Button.

<input type="submit" onclick="javascript:alert('test');" value="Login" name="Login">

I do believe that your onclick for the button should be "onclick="fnbValidateLogin();" .

that doesnt make sense, please be more clear? thanks

do you mean:


theElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("value").Equals("Login") Then
curElement.InvokeMember("onclick="fnbValidateLogin();" . ")
End If
Next
End Sub

I apologize for the confusion. I'm a newbie at JavaScript/HTML.:D

Your original HTML button code should have worked.

<input type="submit" onclick="return fnbValidateLogin();" value="Login" name="Login">

<script type="text/javascript">
    function fnbValidateLogin() {
	alert('Validating Login.');
	}
</script>

Like mentioned, nothing wrong with the original vb.net code you have posted, something is not correct in your HTML code.

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
        For Each curElement As HtmlElement In theElementCollection
            If curElement.GetAttribute("value").Equals("Login") Then
                curElement.InvokeMember("onclick")
                Exit For
            End If
        Next
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.