Clicking a drop down option in iFrame with VBA excel

淺唱寂寞╮ 提交于 2021-02-17 02:15:09

问题


I'm trying to click the drop down option "Approve the Deal" in the below code. I have solid VBA backround but this is my first attempt at HTML automation with VBA excel. Thus far I'm able to navigate and login to the website, select the deal that needs to be approved, and show the drop down. However, I cannot figure out how to click the drop down option/trigger the event. I believe my gaps are dealing with the iFrame and/or table (something I did not have to deal with in the code to this point)

I have tested a lot of different web found code so I won't regurgitate every copy/pasted modied failure I've had. Below is the code I'm attempting to interact with. The "Approve the Deal" is what I'm trying to click/trigger.

Thank you in advance for any advice you could provide!

Edited to include HTML and my code below. I have been deleting non working things and just plugging and playing different options. The piece I identified is likely very wrong.

    <IFRAME id=VCommonBlockerVxActionMenu_68_SUPPORT style="BORDER-TOP: 0px; HEIGHT: 62px; BORDER-RIGHT: 0px; WIDTH: 98px; BORDER-BOTTOM: 0px; POSITION: absolute; LEFT: 1402px; FILTER: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0); BORDER-LEFT: 0px; Z-INDEX: 12; DISPLAY: block; TOP: 98px; BACKGROUND-COLOR: #ffffff; 0: " src="javascript:false" frameBorder=0 scroll="no"></IFRAME>

<DIV id=VxActionMenu_68_SUPPORT class=VDropDown_support style="HEIGHT: 62px; WIDTH: 98px; LEFT: 1402px; Z-INDEX: 13; DISPLAY: inline; TOP: 98px"><TABLE id=VxActionMenu_68_OPTIONS class=VDropDown_options style="WIDTH: 100%" cellSpacing=0 cellPadding=0 border=0>
<COLGROUP>
<COL width=22></COL>
<COL width="100%"></COL>
<COL width=22></COL>
<TBODY>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class="VDropDown_hiderow VDropDown_option" vvalue="null">
<TD class=VDropDown_leftimg>&nbsp;</TD>
<TD class=VDropDown_option>More Actions</TD>
<TD class=VDropDown_rightimg>&nbsp;</TD></TR>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class="VDropDown_option VDropDown_select" vfixed="true" vupdateLabel="true" vjs="VxManager.invokeActionHandler('vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Approve',{statusMsg: 'Approving...'}, {vx_wsid: 'WS3',okHandler:'vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Approve',showDialog:'true',statusMsg:'Approving...'});">
<TD title="Approve the Deal" class=VDropDown_option colSpan=2><NOBR>Approve</NOBR></TD>
<TD class=VDropDown_rightimg><IMG src="http://venprd.na.odcorp.net/vendavo/images/icons/clear.gif" width=16 align=absBottom height=1></IMG></TD></TR>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class=VDropDown_option vfixed="true" vupdateLabel="true" vjs="VxManager.invokeActionHandler('vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Deny',{statusMsg: 'Denying...'}, {vx_wsid: 'WS3',okHandler:'vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Deny',showDialog:'true',statusMsg:'Denying...'});">
<TD title="Deny the Deal" class=VDropDown_option colSpan=2><NOBR>Deny</NOBR></TD>
<TD class=VDropDown_rightimg><IMG src="http://venprd.na.odcorp.net/vendavo/images/icons/clear.gif" width=16 align=absBottom height=1></IMG></TD></TR>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class=VDropDown_option vfixed="true" vupdateLabel="true" vjs="VxManager.invokeActionHandler('vx.publishing.VxPublishingDocActions_OpenOrNew',{statusMsg: 'Publishing...'}, {vx_wsid: 'WS3'});">
<TD title="Create a document from the deal" class=VDropDown_option colSpan=2><NOBR>Publish</NOBR></TD>
<TD class=VDropDown_rightimg><IMG src="http://venprd.na.odcorp.net/vendavo/images/icons/clear.gif" width=16 align=absBottom height=1></IMG></TD></TR></TBODY></TABLE></DIV>

I have another working sub to navigate to the website and login.

Sub VendavoApprove()
    Dim elmButton As MSHTML.IHTMLElement

    'Activate previously opened Vendavo page
    'Set shellWins = New SHDocVw.ShellWindows

    'For Each explorer In shellWins
    'If explorer.Name = "Internet Explorer" Then
    'Debug.Print explorer.LocationURL
    'Debug.Print explorer.LocationName
    'End If
    'Next

    'Set shellWins = Nothing
    'Set explorer = Nothing

    AppTitle = "Powered by Vendavo"

    AppActivate AppTitle

    Set oApp = CreateObject("Shell.Application")

    For i = 0 To 25

        strName = ""

        On Error Resume Next

        strName = oApp.Windows(i).document.URL

        If InStr(strName, "http://venprd.na.odcorp.net/vendavo/pc?page=vx.core.BasicPage&menuId=deals&folderId=quotes") Then

            Set oIE = oApp.Windows(i)

            Exit For

        End If

    Next

    oIE.Visible = True

    oIE.document.all("VTree_VxFolderNav_deals.13.icon").Click
    oIE.document.all("table_VxCanvasListing_inner_1_COL_1_FILTER").Click
    oIE.document.all("table_VxCanvasListing_inner_COL_1_FILTER").Click
    oIE.document.all("table_VxCanvasListing_inner_1_FILTER_VALUE1").Value = 9792365
    oIE.document.all("table_VxCanvasListing_inner_FILTER_VALUE1").Value = 9792365
    oIE.document.all("id1_label").Click
    oIE.document.all("table_VxCanvasListing_inner_1$x0_ROWHDR").Click
    'oIE.document.all("table_VxCanvasListing_inner_1_ActionMenus_LABEL").Click
    oIE.document.all("table_VxCanvasListing_inner_1$x0_1").FireEvent "ondblclick", 1, 2
    oIE.document.all("table_VxCanvasListing_inner$x0_1").FireEvent "ondblclick", 1, 2
    oIE.document.getElementById("VxActionMenu_68_LABEL").Click 'Dynamic
    oIE.document.getElementById("VxActionMenu_67_LABEL").Click 'Dynamic
    oIE.document.getElementById("VxActionMenu_237_LABEL").Click 'Dynamic
    'Approve the core - this is the part I'm working on
    Set htm = oIE.document.frames("VCommonBlockerVxActionMenu_68_SUPPORT").document
    Set frms = htm.forms("TargetForm")
    Set Class1 = frms.document.getElementsByTagName("VxActionMenu_68_OPTIONS")

    For Each inputelement In Class1
        If inputelement.getAttribute("title") = "Approve the Deal" Then
            inputelement.Click
            Exit For
        End If
    Next
    'ending here
    oIE.document.all("VxApprovableComments_71_COMMENT").Value = "Approved"
    oIE.document.all("id1_label").Click

End Sub

回答1:


Looks like tr is outside an iframe and has a mousedown event you can try attaching and firing. I'm targeting the vjs attribute of the tr.

Dim evt As Object
Set evt = .document.createEvent("HTMLEvents")
evt.initEvent "mousedown", True, False

oIE.document.querySelector("[vjs*=VxApprovable_Approve]").dispatchEvent evt


来源:https://stackoverflow.com/questions/58822560/clicking-a-drop-down-option-in-iframe-with-vba-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!