VB: Make webbrowser1 click a button on a webpage - vb.net

Well, I guess title says most of it. I already know how to click a button within a browser but the code doesn't work on this pacific button. I hope this code is allowed on here, sorry if it's not...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button3.Enabled = True
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
For Each webpageelement As HtmlElement In allelements
'AMF Email
WebBrowser1.Document.GetElementById("Email").InnerText textbox1.text
'AMF Password
WebBrowser1.Document.GetElementById("password").InnerText = textbox2.text
'AMF Login Button
If webpageelement.GetAttribute("value") = "Login" Then
webpageelement.InvokeMember("click")
End If
Next
'Navigates to FB likes to begin the process
WebBrowser1.Navigate("http://addmefast.com/free_points/facebook_likes")
Button2.PerformClick()
End Sub
Okay so all this code works perfectly, but now I want it to click the "Like" button on this link: http://addmefast.com/free_points/facebook_likes
However, I can not find the correct value. Can anyone help get the correct value for the "Like" button on that page?
VB2012
When I try to "Inspect Element" on the button, this is all it shows;
<div class="btn3">
Like
</div>

You can use the following code to do this:
For Each elem as HtmlElement in WebBrowser1.Document.All
If elem.GetAttribute("class") = "btn3" Then
elem.InvokeMember("click")
End If
Next
Sorry if there is any mistakes here. I am use to using an IDE for my code...
I hope this helps,
Rodit

Related

COINS.PH login panel from vb.net winform

I want to create a login form for coins.ph but the result isn't what I expected, once I clicked the Sign In button from the form, everything in the username and password textbox will be written in the webbrowser but it wont click the sign in button from the webbrowser. But when I tried clicking the sign in button from the webbrowser, it says that no data were written.
Heres my code:
Private Sub BunifuThinButton21_Click(sender As Object, e As EventArgs) Handles BunifuThinButton21.Click
For Each username As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If username.OuterHtml.Contains("name=""username""") Then
username.SetAttribute("value", BunifuMetroTextbox1.Text)
Exit For
End If
Next
For Each password As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If password.OuterHtml.Contains("name=""password""") Then
password.SetAttribute("value", BunifuMetroTextbox2.Text)
Exit For
End If
Next
For Each signIN As HtmlElement In WebBrowser1.Document.GetElementsByTagName("button")
If signIN.GetAttribute("class") = "login-button login-form__button" Then
signIN.InvokeMember("click")
Timer1.Enabled = False
Exit For
End If
Next
End Sub
Or what other approach should I use which is easier for me, they said that web page changes elements sometime. If api, theres no api for login pages.

GetElementById gives me an exception - VB.NET

I'm working on some code in VB.NET which will do some things automatically.
I have a couple of buttons which will do some actions manually. But I also have one button that does some actions automatically.
If I press the buttons to run it manually, it works fine.
But when I press the button to run it automatically, it gives me an Object reference not set to an instance of an object exception.
This is the code that gives the exception:
Private Sub btnStep4_Click(sender As Object, e As EventArgs) Handles btnStep4.Click
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
Dim ran As Boolean = False
For Each webpageelement As HtmlElement In allelements
WebBrowser1.Document.GetElementById("website_name").SetAttribute("value", txtWebName.Text + txtWebExt.Text) '< This one
WebBrowser1.Document.GetElementById("website_code").SetAttribute("value", txtWebName.Text) '< And this one
If webpageelement.GetAttribute("title") = "Website opslaan" And ran = False Then
webpageelement.InvokeMember("click")
ran = True
End If
Next
End Sub
So when I click the btnStep4 button, it works. But when I simulate the click like this:
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
btnStep4_Click(sender, e)
I get the exception.
Why is this? Is there something I'm missing?
This might be a stupid mistake, but I just can't find out what I'm doing wrong.
Any help or tips would be greatly appreciated!

Auto login to a webbrowser

Hi I am working on a forum project, currently I have a win form that allows the user to login to the forum - this part works fine.
After the user logs in I want a new form to open that will display the forum, how can I use the login details the user entered - pass them to the login form for the website to the user is automatically logged in so to speak
This is the code I am using for user login
If forumLogin.Verify(RadTextBoxUser.Text, RadTextBoxPass.Text) Then
I am using SMF forums not usre how I can pass RadTextBoxUser.Text and RadTextBoxPass.Text to the new form.
I cam accros this code which looked promising
Public Class Browser
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Part 1: Load Yahoo login page in Form_Load event
WebBrowser1.Navigate("http://websiteurl/")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
'Part 2: Locate the Username TextBox and automatically input your username
'<INPUT class=yreg_ipt id=username maxLength=96 size=17 name=login>
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("id").ToString
If controlName = "username" Then
curElement.SetAttribute("Value", LoginForm.RadTextBoxUser.Text)
End If
Next
'Part 3: Locate the Password TextBox and automatically input your password
'<INPUT class=yreg_ipt id=passwd type=password maxLength=64 size=17 value="" name=passwd>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("id").ToString
If controlName = "passwd" Then
curElement.SetAttribute("Value", LoginForm.RadTextBoxPass.Text)
End If
Next
'Part 4: Locate the "Sign In" Button and automatically click it
'<INPUT type=submit value="Sign In" name=.save>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
If curElement.GetAttribute("value").Equals("Sign In") Then
curElement.InvokeMember("click")
'Javascript has a click method for we need to invoke on the current submit button element.
End If
Next
End Sub
End Class
Code taken from http://social.msdn.microsoft.com/Forums/vstudio/en-US/0b77ca8c-48ce-4fa8-9367-c7491aa359b0/yahoo-login-via-systemnetsockets-namespace?forum=vbgeneral
I get an error when the browser loads object doesn't support this property method?
http://prntscr.com/3xygks
Any suggestions?
Ok so I got it working
On a slightly different note you used to be able to re-arrange where the forms would appear when your program runs I don't see that option in VS2012?

Visual Basic: Clicking a button on a webpage

I am trying to make a program click the login button of twitch.tv. I have tried many methods but the thing is that I can not find the button ID of that button. I assume that it doesn't have one and I need help clicking it. What commands would I used to click that button if it has no ID? Here is the HTML of that button
<div class="buttons"> <button class="primary_button" tabindex="10" type="submit"><span class="">Log In</span>
So as you see I have no ID on that button that says Log In.
Basically what I'm asking is, what is the coding command for clicking buttons without a ID. Buttons like this one with no ID, just a class and a type.
The following is my code so far for typing in my log in info but not hitting the submit button
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim allelements As HtmlElementCollection = WebBrowser1.Document.All
WebBrowser1.Document.GetElementById("login_user_login").SetAttribute("Value", "123#gmail.com")
WebBrowser1.Document.GetElementById("user[password]").SetAttribute("Value", "123#gmail.com")
'Type = "submit"
If webpageelement.getattribute("type") = "Log In" Then
webpageelement.invokemember("click")
End If
End Sub
ieDoc = MyBrowser.Document
With ieDoc.forms(0)
.UserName.Value = loguser
.Password.Value = logpasswrd
.submit
End With

how to automatically click search button in google visual basic . net

I have a form with textbox, button and a tabcontrol.
in the button I have this code :
[Dim browser As New WebBrowser()
TabPage1.Controls.Add(browser)
browser.Dock = DockStyle.Fill
browser.Navigate(New Uri("http://www.google.com"))]
The code above works, but I need to be able to search from my textbox and when I click the button it will take me to google and then automatically enter's the word I searched for in my textbox and then clicks the search on google button. I tried this but it does not work. Thanks
Dim textElement. As HtmlElement = browser.Document.All.GetElementsByName("q")(0)
textElement.SetAttribute("value", textbox.text")
Dim btnElement As HtmlElement = browser.Document.All.GetElementsByName("btnG")(0)
btnElement.InvokeMember("click")
I also needed to search in Google Browser with the text the User wanted and by adding the code below to the Button Click Event it did what I wanted.
Code:
Dim sInfo As New ProcessStartInfo("https://www.google.co.in/search?q=" & TXT_Entidade.Text)
Try
Process.Start(sInfo)
Catch ex As Exception
Process.Start("iexplore.exe", sInfo.FileName)
End Try
You'll need to set focus to the textElement before clicking the button.
textElement.Focus()
Otherwise, the page won't run the search apparently.
You can see this by trying the same basic steps you've got above in the Console window. They won't work until the field has had focus (from my testing).
(I also used the mshtml type library so that the click function was directly exposed in the full code below)
Imports mshtml
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
web.Navigate("http://www.google.com")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim textElement As HtmlElement = web.Document.All.GetElementsByName("q")(0)
textElement.SetAttribute("value", TextBox1.Text)
textElement.Focus()
Dim btnElement As HTMLButtonElement =
CType(web.Document.All.GetElementsByName("btnG")(0).DomElement,
HTMLButtonElement)
btnElement.click()
End Sub
End Class
I think you can use this in your button click handler...
browser.navigate("https://www.google.co.in/search?q="+textbox.Text)
This will search Google for the text in your Text Box.
You can search without "automatically clicking the search button" and you do not have to set the value in the text element of the html. This works for me. Hope this helps.