问题
I'm trying to access my webtext a/c using VBA. The first step is trying to get the tag for the username and password input boxes.
I've used inspect elements to determine the tags and I think they are "username" and "password". However, this does not work. Unfortunately, I've no experience of CSS.
Here is my code.
Sub MyLogin()
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "http://www.o2online.ie/o2/login/"
Do Until .ReadyState = 4
DoEvents
Loop
.document.all.Item("username").Value = "MyUsername"
.document.all.Item("password").Value = "MyPassword"
.document.forms(1).submit
End With
End Sub
Any help appreciated.
Regards, Rueful
回答1:
As the login form is inside iframe it may not allow to access the control directly.
Try below code
Sub MyLogin()
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "https://www.o2online.ie/idm/login/lightBoxLogin.jsp?authn_try_count=0&contextType=external&username"
Do Until .ReadyState = 4
DoEvents
Loop
.document.all.Item("username").Value = "MyUsername"
.document.all.Item("password").Value = "MyPassword"
.document.forms(0).submit
.Navigate "http://www.o2online.ie/o2/login/"
End With
End Sub
来源:https://stackoverflow.com/questions/20470634/web-login-using-vba