如何将焦点设置到IE child页面来控制它

How to set focus to IE child page to control it

我一定是遗漏了一些非常简单的东西,但我似乎找不到答案。 这是我用来让我在我的例程中到达特定点的代码:

Dim objShell, IE_count, x, my_url, childPage
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
    On Error Resume Next
    my_url = objShell.Windows(x).document.Location
    If my_url Like "https://a810-dobnow.nyc.gov/Publish/" & "*" Then
        Set childPage = objShell.Windows(x)
        Exit For
    End If
Next
MsgBox my_url

至此,我所有的编码都已成功,我关闭了 IE parent window(我已经抓取了我需要的东西,但我不再需要它了)并且我只剩下 child window 显示,它是 MsgBox 显示的 url。 我的问题是如何将焦点设置到 child window 以便我可以利用它? 我需要做的是按下 child 页面下方的按钮,然后关闭 child window。我知道按钮本身是有效的,因为我已经通过直接访问 url 进行了尝试。 htmlDoc.getElementsByClassName("btn btn-primary btnCustom")(0).点击 但我无法让它工作。 即使这不是正确的方法,如果我什至可以让 child window 关闭,我可以用 url 打开一个新的 IE 实例并从那里继续. 任何帮助将不胜感激。

找到了 设置 IE = childPage 这就是我所需要的