Thanks for taking a look at the question. I am trying to log into a website through VBA. This may have already been answered, but I'm having trouble finding something that works. I've done internet automation with VBA before. I've even used it to log into different sites before, but this one is giving me an issue. I've tried getElementByID, getElementByTagName, etc, but nothing seems to be able to populate the "loginName" and "password" text boxes.
The website is https://vfo.frontier.com/
What I found odd is that when I would go to inspect an element through GoogleChrome Browser it wouldn't take me to the text box I had selected.
Thanks so much in advance. Sorry for any errors, I'm still pretty new to VBA and this is my first post to the site.
The code I have now is below:
Sub FVFO()
Dim IE As InternetExplorerMedium
Dim uRl As String
Dim UserN As Object 'MSHTML.IHTMLElement
Dim PW As Object 'MSHTML.IHTMLElement
Set IE = New InternetExplorerMedium
uRl = "https://vfo.frontier.com/"
With IE
.navigate uRl
.Visible = True
End With
' loop until the page finishes loading
Do While IE.Busy
Loop
' enter username and password in textboxes
Set UserN = IE.document.getElementsByName("loginName")
If Not UserN Is Nothing Then
' fill in first element named "username", assumed to be the login name field
UserN.Value = "login name"
End If
Set PW = IE.document.getElementsByName("password")
' password
If Not PW Is Nothing Then
' fill in first element named "password", assumed to be the password field
PW.Value = "my Password"
End If
End Sub
GetElementsByName
returns a collection of elements -- even if there is only one element, it is still a collection. So, you need to index it correctly. Assuming the first instance of such an element Name is the appropriate one:And likewise:
Results:
Tested in
InternetExplorer.Application
(I don't know what InternetExplorerMedium is...) using late-binding (although that should not matter):The following also works using the
getElementByID
method, which returns a single element (because theid
is unique):