COINS.PH login panel from vb.net winform - vb.net

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.

Related

How to fill a WebForm and click the submit Button with a WebBrowser control?

How can I click this SUBMIT button using a WebBrowser control?
I've tried with:
For Each divSect As HtmlElement In WebBrowser1.Document.GetElementsByTagName("button")
If divSect.OuterHtml.Contains("Accedi") Then
For Each elem As HtmlElement In divSect.Children
If elem.GetAttribute("type") = "button" Then
elem.InvokeMember("click")
End If
Next
End If
Next
but it doesn't return anything.
Here's a sample procedure to perform a WebForm LogIn using a WebBrowser control.
▶ Note: I suggest to activate the WebBrowser Emulation Advanced Features beforehand, in case its need. Read a description here (see the WebBrowserAdvancedFetures class):
(The FEATURE_GPU_RENDERING Key may not exist, so it may be necessary to create it first)
Subscribe to the WebBrowser.DocumentCompleted event before navigating to an Address
As describe in How to get an HtmlElement value inside Frames/IFrames?, the Document may be actually composed of more than one Frame/IFrame (the latter, quite common). If that's the case, you need to handle the DocumentCompleted more than once, since each Frame/IFrame has its own Document
When the event is raised, check whether the WebBrowser.ReadyState is WebBrowserReadyState.Complete: return if its not (we don't want to handle partial documents).
When the current Document is complete find a Form with a specific ID or class name: that's the Login Form we want to fill in.
When the Form is found, parse its Document and to select the INPUT elements that require a value.
If all elements are found and their values has been set, find the SUBMIT Button and call its InvokeMember() method, specifying the click handler to complete the procedure and activate the Form POST method.
When the Button is clicked, the WebBrowser is redirected to a landing page, so we remove the Handler of the DocumentCompleted event: we're done here, handling this event is no longer need.
▶ Set [WebBrowser].ScriptErrorsSuppressed = True in the Form's Designer.
Private Sub btnNavigate_Click(sender As Object, e As EventArgs) Handles btnNavigate.Click
AddHandler webBrowser1.DocumentCompleted, AddressOf Browser_DocumentCompleted
webBrowser1.Navigate("https://SomeAddress.com")
End Sub
Private Sub Browser_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
Dim browser = DirectCast(sender, WebBrowser)
If browser.ReadyState <> WebBrowserReadyState.Complete Then Return
' Select a Form with a specific className
Dim form = browser.Document.Forms.OfType(Of HtmlElement).FirstOrDefault(Function(frm) frm.GetAttribute("className").StartsWith("form-login"))
' Not found at this point, try later
If form Is Nothing Then Return
' Select the element by ID or by className or whatever
Dim userId = form.Document.GetElementById("[The UserId Input's ID]")
' Same for other input elements
Dim userPwd = form.Document.GetElementById("[The Password Input's ID]")
If userId Is Nothing OrElse userPwd Is Nothing Then Return
' Set the value of both Input elements. Note that a validation procedure
' may require that you set both the Value and the InnerText
userId.SetAttribute("value", "[The User LogIn ID]")
'userId.InnerText = "[The User LogIn ID]"
userPwd.SetAttribute("value", "[The User LogIn Password]")
'userPwd.InnerText = "[The User LogIn Password]"
' Filter (fail-safe) the SUBMIT button by className, since - here - it has no ID
Dim submit = browser.Document.GetElementsByTagName("button").OfType(Of HtmlElement).
FirstOrDefault(Function(elm) elm.GetAttribute("type").
Equals("submit") AndAlso elm.GetAttribute("className").Contains("bt-label"))
' The SUBMIT Button was found: click it. Also remove the handler: we're done here
' The WebBrowser is redirected to a landing page, this event is no longer needed
If submit IsNot Nothing Then
RemoveHandler browser.DocumentCompleted, AddressOf Browser_DocumentCompleted
submit.InvokeMember("click")
End If
End Sub

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

VB: Make webbrowser1 click a button on a webpage

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

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.