VBA Open web page, login and get the opened page

て烟熏妆下的殇ゞ 提交于 2019-12-25 09:36:26

问题



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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!