excel - 使用 VBA 导航具有相同窗口标题的第二个窗口
问题描述
我经常浏览一个 Intranet 网站,该网站在单击第一个链接后会打开第二个窗口。我想更改第二个窗口中“textarea”元素的值,但在关注正确的窗口时遇到问题。关于我应该如何继续以下代码以实现我想要做的事情有什么建议吗?
IE.Navigate webPageURL
PageLoadWait 'sub that checks IE.busy and IE.readystate
With IE.Document.Frames("topFrame").document
.getElementById("user")=userID
.getElementById("pwd")=password
.getElementById("submit"). Click
End With
PageLoadWait 'Second window opened
我查看了下面的问题,但不确定如何使其适应我的需要,因为两个窗口的窗口标题相同。我尝试匹配窗口 URL,因为它们略有不同,但由于某种原因无法成功。
解决方案
假设您知道第二个窗口 URL,请尝试下一个功能:
Private Function SecIE(strURL As String) As InternetExplorer
' It needs a reference to 'Microsoft Internet Controls'
Dim objIE As Object
For Each objIE In CreateObject("Shell.Application").Windows
If objIE.Name = "Internet Explorer" Then
If objIE.Document.Location = strURL Then
Set SecIE = objIE: Exit Function
End If
End If
Next
End Function
可以这样调用:
Sub testFindIEObject()
Dim secondIE As InternetExplorer
Set secondIE = SecIE("http://www.msn.com/en-xl/?ocid=iehp&AR=1") 'use your sec Wind URL
Debug.Print secondIE.Document.Title
End Sub
我只是出于测试原因使用他上面的 URL...
如果您不知道,无法提取第二个窗口 URL,我想我可以调整代码以找到第二个,从它的标题开始。必须创建一个静态变量并计算具有相同标题的窗口。第一个窗口将被跳过,第二个窗口将被定义为希望的 IE 对象。
推荐阅读
- spring-boot - Axon Event 仅由我的服务的一个实例而不是全部(扇出)拾取
- tcl - 我们如何检查某个元素是否在 Tcl 列表中不存在?
- c# - HttpActionExecutedContext 响应内容 ReadAsByteArrayAsync 抛出内存异常
- mysql - Prisma 如何可靠地返回最后插入的行,我可以通过过程调用来模拟吗?
- sql - 如何从 SQL 和 IN 条件中的多个表中提取值?
- python - 调用 Python marshmellow sqlAlchemy 对象以将其序列化为 ino json 时超出了最大递归深度
- html - 调整大小时保持图像居中
- android - 对将 API 密钥更改为实时项目的影响?
- laravel - 如何在 laravel 中设置 toIso8601String 时区?
- r - R如何为每年分配相同的值范围