|
第一种:首先用用LocationURL Like 非框架网页 ie和非ie浏览器都可以,但是
运用了框架结构的网页测试不成功
For Each IE In mShellwindows
If IE.LocationURL Like "https://tpass.jiangsu.chinatax.gov.cn:8443/#/login?response_type=code&client_id=s44fftt3bc634tcab4teasbaasba7ft4&redirect_uri=https%3A%2F%2Fetax.jiangsu.chinatax.gov.cn%2Fsso%2FkxLogin%2Fauthorize&lang=en_US*" Then
' 确保页面已加载完成
Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents ' 防止 Excel 冻结
Loop
' 如果页面有框架,则获取正确的框架
' 例如,假设我们要访问第一个框架,可以使用以下代码:
' Set frame = IE.Document.frames(0)
' Set doc = frame.Document
' 在这个例子中,我们假设没有框架,或者我们直接与主文档交互
Set doc = IE.Document
' 现在遍历链接并查找要点击的链接
For Each a In doc.getElementsByTagName("a")
If a.href = "https://tpass.jiangsu.chinatax.gov.cn:8443/#/login?response_type=code&client_id=s44fftt3bc634tcab4teasbaasba7ft4&redirect_uri=https%3A%2F%2Fetax.jiangsu.chinatax.gov.cn%2Fsso%2FkxLogin%2Fauthorize&lang=en_US" Then
' 等待一小段时间以确保 DOM 更新(可选)
Application.Wait (Now + TimeValue("0:00:01"))
a.Click
Exit For ' 找到并点击了链接,退出循环
End If
Next a
Exit For ' 找到并处理了正确的 IE 实例,退出循环
End If
Next IE
Set mShellwindows = Nothing
Set IE = Nothing
第二种:
Public Function getIEInstance(sHTMLPageName As String) As Object
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim objInstances As Object, objIE As Object
Dim sname As String
Set objInstances = CreateObject("Shell.Application").windows
Set getIEInstance = Nothing
If objInstances.Count > 0 Then '/// make sure we have instances open.
err.Clear
For Each objIE In objInstances
On Error Resume Next
sname = objIE.FullName
If UCase(Right(sname, 12)) = "msedge.exe" Then '/// it's internet explorer not windows explorer.
'If InStr(1, LCase(objIE.locationURL), LCase(sHTMLPageName)) <> 0 Then
Set getIEInstance = objIE
Exit For
' End If
End If
sname = ""
Next
End If
Exit Function
errhandler:
If err.Number <> 0 Then
MsgBox err.Description + " " + sname, vbOKOnly, " getIEInstance"
End If
End Function
Private Sub nsrsbh_DblClick(Cancel As Integer)
Dim ieInstance As Object
Dim htmlPageName As String
' 假设您想要查找的页面名(但实际上这个函数不使用这个)
htmlPageName = "https://tpass.jiangsu.chinatax.gov.cn:8443/#/login?response_type=code&client_id=s44fftt3bc634tcab4teasbaasba7ft4&redirect_uri=https%3A%2F%2Fetax.jiangsu.chinatax.gov.cn%2Fsso%2FkxLogin%2Fauthorize&lang=en_US"
' 调用函数尝试获取浏览器实例
Set ieInstance = getIEInstance(htmlPageName)
' 检查是否成功获取了实例
If Not ieInstance Is Nothing Then
' 这里可以添加代码来处理ieInstance,例如访问页面、与页面交互等
'MsgBox "成功获取到浏览器实例!"
ieInstance.Document.parentWindow.execScript ("document.querySelectorAll('input')[1].focus()")
这种方法同样是纯ie浏览器才可以
测试msedge.exe 不成功
第三种是网友发布的“国外大神写的一个类,做了个简单的实例”调用Win32 API,运用管道技术调用文件套接字操作chrome内核浏览器的api接口的
无需任何第三方依赖;但实际测试中 只能每次关闭浏览器重新打开,
第四种结合SeleniumBasic这种需要配置环境且 浏览器打开是独占模式
感叹i比大多数ie爱好者年龄还大的浏览器 惨遭淘汰。。。。
|
|