Unable to access the login Button ..VBA code - vba

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

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

InternetExplorer.Application .contentDocument : <Permission refused>

I'm in France...
I develop in VBA under Excel, I work with the object "InternetExplorer.Application" to browse a website and save the contents.
On the main page there is no problem, but when I load a page that normally opens in a popup, I can not retrieve the contents of the iframe:
<div id="fichecheval" data-zepro="hippodrome=DEAUVILLE&dr=20170826&nr=1&nc=3&nch=1">
<iframe src="//pro.zeturf.com/externe/zefiche_cheval_.php?hippodrome=DEAUVILLE&dr=20170826&nr=1&nc=3&nch=1&ts=1503747108&key=aecd0f4c33ce9588e38d7f8c6986ec778beeb88fffb940f07cfda0ec4a7768ab" frameborder="0" scrolling="yes" style="min-height: 5000px;">
</iframe>
</div>
my code :
Dim IFrame As HTMLDocument
Dim Content As Object
Dim html As HTMLDocument
Dim FormulaireConnexion As Object
Dim login As Object
Dim Password As Object
Dim jour As Object
Dim mois As Object
Dim annee As Object
Dim MyTag As Object
'Références et zones de chargement
Dim MyAdr As String
'Gestion fichiers
Dim intFic As Integer
Dim MyFile As String
'******************************************
'Instantiation InternetExplorer.Application
'******************************************
Set IE = CreateObject("InternetExplorer.Application")
'IE.Silent = True
IE.Visible = True
'*******************************
'Connexion avec authentification
'*******************************
IE.navigate "https://www.zeturf.fr"
Do
DoEvents
Loop While IE.readyState <> 4 And IE.Busy = True
Sleep 1000
Set login = IE.document.getElementById("connection_login")
login.Value = "toto"
Set Password = IE.document.getElementById("connection_password")
Password.Value = "toto66"
Set jour = IE.document.getElementById("connection_jour")
jour.Value = "01"
Set mois = IE.document.getElementById("connection_mois")
mois.Value = "01"
Set annee = IE.document.getElementById("connection_annee")
annee.Value = "1966"
Set FormulaireConnexion = IE.document.getElementById("connection_submit")
FormulaireConnexion.Click
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE And IE.Busy = False
Sleep 1000
'*****************
IE.navigate "https://www.zeturf.fr/fr/course/2017-08-26/R1C3-deauville-prix-de-la-reconversion-des-chevaux-de-courses-grand-handicap-de-la-manche/turf"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE And IE.Busy = False
Sleep 1000
'*****************
MyAdr = "https://www.zeturf.fr/fr/course/2017-08-26/R1C3-deauville-prix-de-la-reconversion-des-chevaux-de-courses-grand-handicap-de-la-manche/turf/partants/2412257"
'_blank Load the link into a new unnamed window.
'_parent Load the link into the immediate parent of the document the link is in.
'_self Load the link into the same window the link was clicked in.
'_top Load the link into the full body of the current window.
IE.navigate MyAdr, , "_self"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE And IE.Busy = False
Sleep 1000
'*****************
MyFile = ThisWorkbook.Path & "\Courses\test.html"
intFic = FreeFile
Open MyFile For Output As intFic
Print #intFic, IE.document.body.innerHTML
'*****************
Set IFrame = IE.document.frames().document.getElementsByTagName("iframe")(0)
Set Content = IFrame.getElementsByTagName("html")
Set IFrame = Nothing
'*****************
Close intFic
On the "Set Content" I have the error "Permission denied" and when I look at the IFrame object in the spy window I have this:
IFrame: contentDocument:
I tell myself that my navigation does not simulate the reality (no popup), but opening in the same tab or a second tab ...
Do you have any idea about the problem? Thank you for your help

Login to Bank using 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.

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.

getelementbyid via msexcel vba object required 424

I have been struggling to get the getelementbyid (or name) code working. What I want to do is submit login details without using sendkeys. Probably is just a matter of not understanding the website. I can view the element by
MsgBox (Mid(ObjIE.Document.frames(1).Document.body.outerHTML, 1800, 1000))
which shows id= userName and name = userName. But when I try to getelementbyid it comes up with an object required error, as if its not there.
Here you go
Instead of this URL http://fieldwork.genesisenergy.co.nz/
I am directly navigating to below frame src
<frame name="Login" src="LoginGenesis.aspx?bgColor=FFFFFF&trimColor=FF6600" frameBorder="0" marginWidth="0" marginHeight="0" scrolling="auto">
Sub Website()
Dim IE As Object, Doc As Object, UserName As Object, Password As Object, strCode As String
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
' IE.navigate "http://fieldwork.genesisenergy.co.nz/"
IE.navigate "http://fieldwork.genesisenergy.co.nz/LoginGenesis.aspx?bgColor=FFFFFF&trimColor=FF6600"
Do While IE.readystate <> 4: DoEvents: Loop
Set Doc = CreateObject("htmlfile")
Set Doc = IE.document
Set UserName = Doc.getelementbyid("userName")
UserName.Value = "santosh"
Set Password = Doc.getelementbyid("userPassword")
Password.Value = "santosh#123"
Set btnLogin = Doc.getelementbyid("loginUser")
btnLogin.Click
End Sub