Login with no ID

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
779
Office Version
  1. 365
Hi,

Want log in to a website automatically with vba but the problem I am having when I inspect the login box there's no ID HTML only what's in the picture below, tried using this line of code but doesn't work:

Code:
HTMLDoc.getElementById("login").Value = Worksheets("Portal_Access").Range("F20")

Page source:
<input type="text" class="form-control" tabindex="1" id="LoginUsernameTextBox">

<input type="text" class="form-control" tabindex="1" id="LoginUsernameTextBox">

thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
The 2 input boxes you posted have this HTML:

HTML:
< input type="text" class="form-control" tabindex="1" id="LoginUsernameTextBox">
Therefore try:

Code:
HTMLDoc.getElementById("LoginUsernameTextBox").Value = Worksheets("Portal_Access").Range("F20").Value
 
Last edited:
Upvote 0
Thanks.

But I tried and it game Run-time error 424 object required. here is the complete code:

Code:
Sub CityWest()Dim IE As Object
Dim HTMLDoc As Object
Dim objCollection As Object
Dim ws As Worksheet
    
  
  'On Error GoTo Err_Clear
  Const navOpenInNewTab = &H800
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  ShowWindow IE.hwnd, SW_MAXIMIZE
  IE.navigate "https://citywest.smarthub.coop/Login.html"
  Do While IE.Busy Or IE.readyState <> 4: Loop


  Set HTMLDoc = IE.document


  With HTMLDoc
  HTMLDoc.getElementById("LoginUsernameTextBox").Value = Worksheets("Portal_Access").Range("F20").Value
  HTMLDoc.getElementByClassName("LoginPasswordTextBox").Value = Worksheets("Portal_Access").Range("G20")
 
  
  
  
  End With
  Set objCollection = IE.document.getElementById("LoginSubmitButton")
  objCollection.Click
  
'Err_Clear:
'If Err <> 0 Then
'Err.Clear
'Resume Next
'End If
 
End Sub
 
Upvote 0
Both login input fields have an id. You want getElementById, not getElementByClassName, which isn't a valid method.

Try this macro:
Code:
Public Sub IE_Login2()

    With CreateObject("InternetExplorer.Application")
        .navigate "https://citywest.smarthub.coop/Login.html"
        .Visible = True
        While .Busy Or .readyState <> 4: DoEvents: Wend
        Do
            DoEvents
        Loop Until InStr(1, .document.body.outerHTML, "LoginUsernameTextBox", vbTextCompare)
        
        .document.getElementById("LoginUsernameTextBox").Value = "YourEmailAddress"
        .document.getElementById("LoginPasswordTextBox").Value = "YourPassword"
        .document.getElementById("LoginSubmitButton").Click
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,064
Members
448,941
Latest member
AlphaRino

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top