无法通过VBA单击PopUp窗口中存在的元素

尊敬的专家,我正在开发我的下面的VBA代码,我不能点击一个元素通过VBApopup窗口中呈现。

Sub GoToWebsiteTest() Dim appIE As InternetExplorerMedium Dim tags As Object Dim tagx As Object Dim repo As Object Dim Element As HTMLButtonElement Dim MyHTML_Element As IHTMLElement Dim HTMLdoc As HTMLDocument i = 0 Set appIE = New InternetExplorerMedium sURL = "https://oneview.myurl.in/" With appIE .navigate sURL .Visible = True End With Do While appIE.Busy Or appIE.readyState <> 4 DoEvents Loop appIE.document.getElementById("Username").Value = "xxx" appIE.document.getElementById("Password").Value = "xxxx" i = InputBox("type") appIE.document.getElementById("txtcaptcha").Value = i Set tags = appIE.document.getElementsByTagName("input") For Each tagx In tags If tagx.Type = "submit" Then tagx.Click End If Next Do While appIE.Busy Or appIE.readyState <> 4 DoEvents Loop Set HTMLdoc = appIE.document Set e = HTMLdoc.getElementById("ctl00_MainContent_gridUser_ctl00_ctl04_lnkG2") e.Click 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 my_title = objShell.Windows(x).document.Title If my_title Like "Back Office" & "*" Then Set ie = objShell.Windows(x) Set HTMLdoc1 = objShell.Windows(x) Exit For Else End If Next 

直到这里我的代码完全正常工作,请帮助我如何处理popup窗口,并单击popup窗口中所需的元素。我已经尝试了下面的代码,但它不工作。

 With HTMLdoc1 .Visible = True End With Set f = HTMLdoc1.document.all.Item("Click to enter Share Transactions") f.Click End Sub 

我也试过下面的每个循环,但没有达到我的目的。

 Set f = HTMLdoc1.document.getElementsByTagName("div") For Each ti In f If ti.Title = "Click to enter Share Transactions" Then ti.Click End If Next 

HTML代码同样如下:

 <div class="topFolder" id="a2" title="Click to enter Share Transactions" style="color: red; background: rgb(228, 246, 248); border-width: 1px 1px 0px; border-left-style: solid; border-left-color: rgb(228, 246, 248); border-right-style: solid; border-right-color: rgb(228, 246, 248); border-top-style: solid; border-top-color: rgb(228, 246, 248); border-bottom-style: initial; border-bottom-color: initial; padding-bottom: 3px;"><img class="icon" height="17" src="/cgi-bin/images/bl.gif" width="19"><nobr>Share Transactions</nobr></div> 

在这里输入图像说明

进入特定的框架

 Dim iFrm As HTMLIFrame Set iFrm = HTMLdoc1.document.frames("fraToc").document.getElementById("aMenu") 

在这里输入图像说明

input特定的框架,然后单击特定的元素

 Dim iFrm As MSHTML.HTMLWindow2 Dim HTMLdocc As HTMLDocument Set iFrm = HTMLdoc1.document.frames("fraToc").document.getElementById("aMenu") Set iFrm2 = iFrm.getElementsByTagName("div") For Each divi In iFrm2 If divi.ID = "a2" Then divi.Click End If Next 

在这里输入图像说明