Mike R. Mike R. - 1 year ago 129
Vb.net Question

How to get button using VB.NET

I am not sure how to invoke a button click using VB.NET:

<form id="form-login" style="clear: both;" name="login" method="post" action="index.php">
<p id="form-login-username">
<label for="modlgn_username">Username</label>
<input id="modlgn_username" class="inputbox" type="text" size="15" name="username">
<p id="form-login-password">
<p id="form-login-lang" style="clear: both;">
<div class="button_holder">
<div class="button1">
<div class="next">
<a onclick="login.submit();"> Login</a>
<div class="clr"></div>
<input type="submit" value="Login" style="border: 0; padding: 0; margin: 0; width: 0px; height: 0px;">
<input type="hidden" value="com_login" name="option">
<input type="hidden" value="login" name="task">
<input type="hidden" value="1" name="19c1f84e789e8862fce26aa45d57a980">

What I am trying to do is use this line of code to invoke a button click once the webpage is fully loaded. Everything works except the click, I am not sure how to get the button.

WebBrowser1.Document.GetElementsByTagName(" ... ").InvokeMember("click")

I tried a bunch of stuff for ... but none of it works. Would really appreciate any feedback.


Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If Me.WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
WebBrowser1.Document.GetElementById("username").SetAttribute("value", "admin")
WebBrowser1.Document.GetElementById("passwd").SetAttribute("value", "...")
End If
End Sub

Answer Source

It might be easier to submit the form instead.

Dim form As HtmlElement = WebBrowser1.Document.GetElementById("form-login")

If form IsNot Nothing Then
End If
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download