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

时间:2017-02-14 09:24:43

标签: jquery excel vba excel-vba

尊敬的专家,我正在开发我的以下VBA代码,我无法通过VBA点击PopUp窗口中的元素。

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

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

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>

enter image description here

进入特定框架

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

enter image description here

进入特定框架并单击特定元素

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

enter image description here

0 个答案:

没有答案