自动登录财付通,难点在于会出现验证码,并且验证码页是在iframe元素下的,出于各种安全考虑,webbrowser控件不提供这种访问机制!当然,第一想到的是将这个网页拿出来,可是输入完毕验证码后,点击“确定”需要与原网页交互,而此时已经脱离原网页,所以不能实现跳转。查找好久,还是找到了访问ifame内元素的解决办法:
需要引入这三个引用: 对于选中的那个,如果没有,可以在这儿下载
下面直接看源代码:

Private Sub goto_Click() For j = 0 To 2 Set WebBrowser1.Document.cookie = Nothing WebBrowser1.Navigate2 ("https://xui.ptlogin2.tenpay.com/cgi-bin/xlogin?appid=546000248&style=34&hide_border=1&proxy_url=https%3A%2F%2Fwww.tenpay.com%2Fv2%2Fproxy.html&target=self&daid=120&s_url=https%3A%2F%2Fwww.tenpay.com%2Fv2%2Fres%2Fjs%2Fyui%2Fbuild%2Flogin%2Fptlogin.shtml&pt_no_auth=1&v=10063002#1444282478405") Do DoEvents If WebBrowser1.ReadyState = READYSTATE_COMPLETE Then 'MsgBox "载入完成": Exit Do End If Loop Set vDoc = WebBrowser1.Document vDoc.All(2).Click Dim i As Integer For i = 0 To vDoc.All.length - 1 If UCase(vDoc.All(i).id) = "U" Then 'vDoc.All(i).Click 'MsgBox vDoc.All(i).id: vDoc.All(i).Value = "*******帐号" End If If UCase(vDoc.All(i).id) = "P" Then 'vDoc.All(i).Click 'MsgBox vDoc.All(i).id: vDoc.All(i).Value = "*******密码" End If Next For i = 0 To vDoc.All.length - 1 If UCase(vDoc.All(i).id) = "LOGIN_BUTTON" Then 'MsgBox vDoc.All(i).id vDoc.All(i).Click End If Next If j = 2 Then While WebBrowser1.Busy DoEvents Wend Set vDocFrame = getFrames(WebBrowser1).Document For i = 0 To vDocFrame.All.length - 1 If UCase(vDocFrame.All(i).id) = "CAP_INPUT" Then vDocFrame.All(i).Value = "szbv" End If Next For i = 0 To vDocFrame.All.length - 1 If UCase(vDocFrame.All(i).innerText) = "确 定" Then vDocFrame.All(i).Click While WebBrowser1.Busy DoEvents Wend WebBrowser1.Navigate ("https://www.tenpay.com/app/v1.0/cftaccount.cgi") Exit For End If Next 'If UCase(vDocFrame.All(i).id) = "CAP_INPUT" Then 'MsgBox vDocFrame.All(0).id 'End If End If 'vDoc.All(75).Click Next End Sub '取出iframe对象 'WB为要处理的webbrowser Private Function getFrames(ByVal WB As WebBrowser) As Object Dim pContainer As olelib.IOleContainer Dim pEnumerator As olelib.IEnumUnknown Dim pUnk As olelib.IUnknown Dim pBrowser As SHDocVwCtl.WebBrowser_V1 Set pContainer = WB.Object.Document If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then Set pContainer = Nothing Do While pEnumerator.Next(1, pUnk) = 0 Set pBrowser = pUnk If Err.Number = 0 Then Print "Frame: " & pBrowser.LocationURL If InStr(1, pBrowser.LocationURL, "https://ssl.captcha.qq.com/cap_union_show") Then '可以在这里加条件判断得到指定的frame,基本可以根据url或者innerHTML中的某个关键字符 Set getFrames = pBrowser Exit Function End If End If Loop Set pEnumerator = Nothing End If End Function