Reputation: 29
I need use webBrowser Control to auto click one button on website. I know how to write code if I can get ( Name or Id ), but this website not set button name or ID.
Here is code button on website:
<input type="submit" alt="Login" value="Login"/>
How am I supposed to use vb webBrowser control in this case?
Upvotes: 1
Views: 4643
Reputation: 659
You shouldn't be using the web browser control to do any such thing (I also assume you mean you're using System.Windows.Forms.WebBrowser in a WinForms app or the WPF equivalent in a WPF application)
If you need to 'click' a button on a web page.. what you really mean is that you need to submit an HTTP request to the website.
So, let's say your target website has something like this... and you want to click the 'submit' button.. but like you said, it has no id.
<form action="http://example.com/foo/bar/login" method="POST">
<input type="text" id="username" />
<input type="password" id="password" />
<input type="submit" alt="Login" value="Login" />
</form>
Here is an example of how to accomplish this in C#: post data through httpWebRequest
To accomplish the same thing in VB.NET you'd use:
Dim request As New WebRequest.Create("http://example.com/foo/bar/login")
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
Using (Dim writer As New StreamWriter(request.GetRequestStream()))
writer.Write("username=whatever")
writer.Write("password=p@$$w0rD")
End Using
Dim response = request.GetResponse()
Upvotes: 1