VBA Open web page, login and get the opened page

2019-09-18 15:46发布


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条回答
看我几分像从前
2楼-- · 2019-09-18 16:39

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
查看更多
登录 后发表回答