Login to Bank using VBA - vba

I am hoping to complete 2 simple tasks. Input the password, and submit username and password to https://ktt.key.com
I am currently able to display my name in the username tab, but am having trouble entering password. Please provide way to submit too. Thanks for the help guys.
This is what I have so far...
Sub login()
Dim IE As Object
Dim HTMLDoc As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://ktt.key.com/ktt/cmd/logon"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.document
Set htmlColl = HTMLDoc.getElementsByName("moduleTarget")
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx"
End With
End Sub

I noticed you have objCollection set as an Object, so I will be using that one to populate your password field.
Change:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx"
End With
To:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
End With
And then under that, paste:
Set objCollection = HTMLDoc.getelementsbyname("txtPassword")
objCollection(0).Value = "1234" 'This is your password
So what this does it, it set a new object to the txtPassword Element collection. Then it takes the first index (there's only one index here under "txtPassword") and assigns the value of your choice. The full code (from With HTMLDoc down) should look like this:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
End With
Set objCollection = HTMLDoc.getelementsbyname("txtPassword")
objCollection(0).Value = "1234" 'This is your password
Let me know if this works for you.

Related

How to execute (Login) button on specific website?

I found this VBA code online and it works on Facebook for example.
On https://www.solarmanpv.com/portal/LoginPage.aspx it does not work. It opens Internet Explorer, puts the credentials on the right places but won't press login.
Error '424' is shown on VBA when I try to run.
Sub LoginViaBrowser()
Dim Dc_Usuario As String
Dim Dc_Senha As String
Dim Dc_URL As String
Dim objIE As New InternetExplorer 'Referencie "Microsoft Internet Controls"
objIE.Visible = True
Dc_Usuario = "user#email.com"
Dc_Senha = "pass"
Dc_URL = "https://www.solarmanpv.com/portal/LoginPage.aspx"
objIE.Navigate2 Dc_URL
Do Until objIE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
objIE.document.all("uNam").innertext = Dc_Usuario
objIE.document.all("uPwd").innertext = Dc_Senha
objIE.document.all("login").submit
End Sub
Please try to use F12 developer tools to check the html elements, then, you could find that the id of the login button is "Loginning", not "login".
Try to modify your code as below:
Sub LoginViaBrowser()
Dim IE As Object
Dim Dc_Usuario As String
Dim Dc_Senha As String
Dim Dc_URL As String
Dim txtNam As Object, txtPwd As Object
Dc_Usuario = "user#email.com"
Dc_Senha = "pass"
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "https://www.solarmanpv.com/portal/LoginPage.aspx"
While IE.ReadyState <> 4
DoEvents
Wend
IE.Document.getElementById("uNam").Value = Dc_Usuario
IE.Document.getElementById("uPwd").Value = Dc_Senha
IE.Document.getElementById("Loginning").Click
End With
Set IE = Nothing
End Sub
Have you tried calling a click on it by id?
IE.Document.getElementById("Loginning").Click

Unable to access the login Button ..VBA code

Sub login()
Dim IE As Object
Dim HTMLDoc As Object, HTMLDoc2 As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https:///CWRWeb/displayMemberLogin.do"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.Document
With HTMLDoc
HTMLDoc.getElementByID("userID").Value = "yyyy" 'Entering credential
HTMLDoc.getElementByID("passwd").Value = "xxxxx"
End With
Set objCollection = IE.Document.getElementByID("login-s")
objCollection.Click
End Sub
I am unable to automate the login click. The login button does not have an ID for input. I am not sure what to use to get the handle .getElementBy....
The form has a name - you can submit it directly after you fill in the username and password
HTMLDoc.Forms("loginFormBean").submit

How Do I enter username and Password on a webpage?

Q1)How do I enter the password and username on this webpage"https://.com/1/19/login.esp" ?
I have written the code to access the webpage:
Sub login()
Dim IE As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://esp"
End Sub
Q2) what createobject should I use to access google chrome?
Thnx in advance
To find items on a webpage to select through VBA, you need to step into the Developer tools on the webpage by pressing F12.
Once there, you can find the elements you want to call by "stepping into" the code on the page and selecting the items you wish VAB to select.
Here is how that is done:
Then select the username box:
After selecting this box, the code in the developer box will be highlighted, telling you what the code is that is linked to the item you pressed.
Here is the now highlighted code for the username box:
We have three options to select the item on the page:
IE.document.getElementById (find the ID= in the code, here id='USERNAME')
IE.document.getElementsByName (find the Name= in the the code, here name='USERNAME')
IE.document.getElementsByclassname (find the class= in the code. In this case, class='focus')
*Note: Try to use to use the ID first, then name, then class as only 1 element on the page will have that 1 ID, but multiple items can have the same name or class, or its guaranteed to work if you have the correct ID.
Dim IE As Object ' InternetExplorer.Application
Dim UserN As Object 'username field
Dim PW As Object 'password field
Dim LoginButton As Object 'Login button
'enter username and password in textboxes
Set UserN = IE.document.getElementByID("USERNAME")
'fill in first element named "username", assumed to be the login name field
UserN(0).Value = ""
Set PW = IE.document.getElementsByName("PASSWORD")
'fill in first element named "password", assumed to be the password field
PW(0).Value = ""
Then you need to find the botton on the page, and click it.
Here is some code for that:
'After entering in the user/pass, we need to click the button.
Dim objCollection As Object
Set objCollection = IE.document.getElementById("loginbutton")
objCollection.Click
There is a ton more info out there and more code on how to properly use each selection method, so this is just the barebones to get you started.
Searching for 'VBA IE automation' will get you some good results to work with.
Sub login()
Dim IE As Object
Dim HTMLDoc As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://ogin.esp"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.document
With HTMLDoc
HTMLDoc.getElementById("USERNAME").Value = "yyyy"
HTMLDoc.getElementById("PASSWORD").Value = "xxxxx"
End With
Set objCollection = IE.document.getElementById("loginbutton")
objCollection.Click
End Sub
This code works....

Issue with finding element on Amazon Seller homepage with VBA code

I recently came across a new problem while working with my Excel VBA code in order to automate the input a value from a cell (order number) into Amazon's search box and searching for the order. I can't seem to locate the proper object to reference the search button on the homepage of the Amazon Seller home page in order to click and proceed. My code is this:
Option Explicit
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub MyAmazonSeller()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim oSignInLink As HTMLLinkElement
Dim oInputEmail As HTMLInputElement
Dim oInputPassword As HTMLInputElement
Dim oInputSigninButton As HTMLInputButtonElement
Dim oInputSearchOrder As HTMLInputElement
Dim oInputSearchButton As HTMLInputButtonElement
MyURL = "https://sellercentral.amazon.com/gp/homepage.html"
Set MyBrowser = New InternetExplorer
' Open the browser and navigate.
With MyBrowser
.Silent = True
.Navigate MyURL
.Visible = True
Do
DoEvents
Loop Until .ReadyState = READYSTATE_COMPLETE
End With
' Get the html document.
Set HTMLDoc = MyBrowser.Document
' See if you have the sign in link is because you are in the main
' page
Set oSignInLink = HTMLDoc.getElementById("signin-button-container")
If Not oSignInLink Is Nothing Then
oSignInLink.Click
Do
DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
End If
' Get the email field and the next button
Set oInputEmail = HTMLDoc.getElementById("username")
Set oInputPassword = HTMLDoc.getElementById("password")
' Click the button and wait
oInputEmail.Value = "xxxxxxxxx#xxxxxx.net"
' Get the password field and the sign in button
Set oInputPassword = HTMLDoc.getElementById("password")
Set oInputSigninButton = HTMLDoc.getElementById("sign-in-button")
' Click the button and wait
oInputPassword.Value = "xxxxxxxx"
oInputSigninButton.Click
Do
DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set oInputSearchOrder = HTMLDoc.getElementById("sc-search-field")
oInputSearchOrder.Value = "110-7706193-5695453"
Set oInputSearchButton = HTMLDoc.getElementByClassName("sc-search-button")
oInputSearchButton.Click
Do
DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
The section right before the Err_Clear is the new snippet of code I've been trying to modify and work with. It seems that the search button does not have a proper ID, so therefore is more difficult to reference. I am getting an Error 91 every time the code gets to the second to last snippet.

VBA: Wait until browser loads more than once

I've been working on a program to fill up a form after the webpage is loaded, its working well with this:
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
After this my code loads, fills up the form and the click the log in button.
Here comes the problem, i've been trying to click a button right after the new page loads, so i tried the same loop method to accomplish this, but it is not working.
I said to myself, this can't be, it has to work!, so i tried making a code for a search on youtube and for my surprise it did work, it searched a video and then i could select the one i wanted.
So if it does work, why it doesnt with my login page?
I noticed the page does not reach the next page right away after logging in, it loads a page and then quickly it loads another one and reroutes to that one.
Do you have any idea how to wait until the browser reaches that point?
whole code until now:
Private Sub CommandButton3_Click()
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "url"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.user.Value = "user"
HTMLDoc.all.pass.Value = "pass"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("img")
If MyHTML_Element.getAttribute("src") = "url" Then MyHTML_Element.Click: Exit For
Next
Set MyBrowser.document = HTMLDoc
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("img")
If MyHTML_Element.getAttribute("name") = "name" Then MyHTML_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub