问题
Hi all, in my Access & VBA small application a function opens a web page, fills the username and password and then login.
How can I read text field and other contents from the opened web page just after login and not in a new web page with the same link of the opened?
This is my code.
Thank all
Private Sub myButton_Click()
Dim IE As Object
Dim IEDoc As HTMLDocument
Set IE = CreateObject("InternetExplorer.application")
Set IEDoc = IE.Document
IE.Navigate "http://mylogin.com"
Do While IE.Busy: DoEvents: Loop
While IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
With IEDoc
.getElementsByName("userid")(0).Value = "user"
.getElementsByName("password")(0).Value = "password"
.getElementById("btn_login").Click
End With
'At this point, I would read a text field from the new opened page, after login, in the same browser (not from a new webpage with the same link)
回答1:
you add a wait for the answer page on the click button, then you access the textfield value by its name
Private Sub myButton_Click()
Dim IE As Object
Dim IEDoc As HTMLDocument
Set IE = CreateObject("InternetExplorer.application")
Set IEDoc = IE.Document
IE.Navigate "http://mylogin.com"
Do While IE.Busy: DoEvents: Loop
While IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
With IEDoc
.getElementsByName("userid")(0).Value = "user"
.getElementsByName("password")(0).Value = "password"
.getElementById("btn_login").Click
End With
'At this point, I would read a text field from the new opened page, after login, in the same browser (not from a new webpage with the same link)
Do While IE.Busy: DoEvents: Loop
While IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
With IEDoc
msgbox .getElementsByName("thetextfield").Value
End With
来源:https://stackoverflow.com/questions/43569876/vba-open-web-page-login-and-get-the-opened-page