I am using the below code to enter the server page. I am inspecting the html code and fill the data accordingly. Filling Username and passwords are success, but login button is not working. The code posted below. Instead of calling IExplorer, I am using activX name it as WebCamVBA for my SCADA.
Private Sub Display_AnimationStart()
Dim HTMLDocs As HTMLDocument
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "http://192.168.1.1/"
WebCamVBA.Silent = True
WebCamVBA.Navigate (MyURL)
WebCamVBA.Visible = True
Do
Loop Until WebCamVBA.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = WebCamVBA.Document
HTMLDoc.all.username.Value = "admin1"
HTMLDoc.all.password.Value = "*****"
For Each MyHTML_Element In HTMLDoc.getElementsByName(“input”)
If MyHTML_Element.Type = “login” Then MyHTML_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
Login button html code provided below
CodePudding user response:
Does this work for you?
Option Explicit
Sub WbClkMe()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLButton As MSHTML.IHTMLElement
IE.Visible = True
IE.navigate "https://apiweb.biomerieux.com/login"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.document
Set HTMLInput = HTMLDoc.getElementById("signupEmail") ' This is based on on your website
HTMLInput.Value = "" 'Put the value of Usernamae
Set HTMLInput = HTMLDoc.getElementById("signupPassword") 'This is based on on your website
HTMLInput.Value = "" 'Put the value of Password
Set HTMLButton = HTMLDoc.getElementById("signupSubmit") 'This is based on on your website
HTMLButton.Click
End Sub
Or, maybe this?
Sub WebsiteLogin()
Const url As String = "https://login.my_site_here.jsp"
Const userName As String = "Here Your LogIn Name"
Const passWord As String = "Here Your Password"
Dim ie As Object
Dim htmlDoc As Object
Dim nodeInputUserName As Object
Dim nodeInputPassWord As Object
'Initialize Internet Explorer, set visibility,
'call URL and wait until page is fully loaded
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate url
Do Until ie.readyState = 4: DoEvents: Loop
Set htmlDoc = ie.document
'Set the log in name
Set nodeInputUserName = htmlDoc.getElementById("USERID")
nodeInputUserName.Value = userName
Call TriggerEvent(htmlDoc, nodeInputUserName, "onkeypress")
'Set the password
Set nodeInputPassWord = htmlDoc.getElementById("PASSWORD")
nodeInputPassWord.Value = passWord
Call TriggerEvent(htmlDoc, nodeInputPassWord, "onkeypress")
'Click submit button
htmlDoc.querySelector("a[role='button']").Click
End Sub
' This is the procedure to trigger events:
Private Sub TriggerEvent(htmlDocument As Object, htmlElementWithEvent As Object, eventType As String)
Dim theEvent As Object
htmlElementWithEvent.Focus
Set theEvent = htmlDocument.createEvent("HTMLEvents")
theEvent.initEvent eventType, True, False
htmlElementWithEvent.dispatchEvent theEvent
End Sub
CodePudding user response:
I got the solution. Even it is java script, it is working with the below code
For Each Element In MyHTML_Element.Links
If InStr(MyHTML_Element.innerText, "Login") Then
Call MyHTML_Element.Click
Application.Wait (Now() TimeValue("00:00:3"))
End If
Next