dispatchEvent - VBA IE 自动化 [英] dispatchEvent - VBA IE automation

查看:35
本文介绍了dispatchEvent - VBA IE 自动化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我似乎无法找到有关如何在 VBA 中调度事件的答案.

I have a question I can't seem to figure out the answer to regarding how to dispatch an event in VBA.

在我尝试通过 VBA 导航的网站上,有一个动态表 id="G_grdProfile".在表格 html 中,列出了事件.表格本身是动态的.至少总会有一行 id="grdProfile_r_0".在该行中,有可以单击的单元格.可以有 id="grdProfile_rc_0_0", grdProfile_rc_0_1" 等

On the website I am trying to navigate via VBA, there is a dynamic table id="G_grdProfile". In the table html, there are events listed. The table itself is dynamic. At minimum there will always be a row with the id="grdProfile_r_0". Within that row, there are cells that can be clicked. There can be id="grdProfile_rc_0_0", grdProfile_rc_0_1", etc.

我假设我需要调度与行或行中的单个单元格相关的事件,但我似乎无法让它工作.通过在 Chrome 和 IE 中使用开发人员工具,看起来当单击单元格(17 以外)时会触发 ondblclick 或 onmousedown 事件.并且 .click 不会返回错误,但不会执行任何操作.

I assume I need to dispatch the event in relation to the row or individual cell within the row, but I can't seem to get it to work. From using developer tools in Chrome and IE, it looks like either the ondblclick or onmousedown events are fired when a cell (other than 17) is clicked. And .click does not return an error, but does not do anything.

我的代码是:

     With ie
 While .Busy Or .ReadyState <> 4: DoEvents: Wend
 Application.Wait (Now + TimeValue("0:00:02"))
 Set objLink = .Document.frames("mainParent").Document.forms("AgentProfileList").Document.getElementById("G_grdProfile").Document.getElementById("grdProfile_r_0").Document.getElementById("grdProfile_rc_0_2")
 objLink.dispatchEvent ("onmousedown")
 End With        

本节上面引用的 HTML 是:

The HTML referenced above for this section is:

<TABLE onmouseup='igtbl_cellClickUp(event,"grdProfile");' onmouseover='igtbl_cellMouseOver(event,"grdProfile");' ondblclick='igtbl_cellDblClick(event,"grdProfile");' onmousemove='igtbl_cellMouseMove(event,"grdProfile");' onmousedown='igtbl_cellClickDown(event,"grdProfile");' onmouseout='igtbl_cellMouseOut(event,"grdProfile");' id=G_grdProfile onselectstart='igtbl_selectStart(event,"grdProfile");' style="WIDTH: 978px; TABLE-LAYOUT: fixed; POSITION: relative" oncontextmenu='igtbl_cellContextMenu(event,"grdProfile");' cellSpacing=0 cellPadding=0 border=0 bandNo="0"><COLGROUP>

<TR id=grdProfile_r_0 style="HEIGHT: 20px" DataKey="XXXXX3658"><TD id=grdProfile_rc_0_0 class="ig_2e49b359_r1 GRSHand"><NOBR><SPAN id=fup_agentstdsearch_3765545><A onclick='javascript:xfupshow("fup_agentstdsearch_3765545");' href="javascript:void(0);"><IMG border=0 src="https://xchange.reged.com/ctiacom/images/flag000.gif"></A></SPAN>&nbsp;&nbsp;</NOBR></TD>
<TD id=grdProfile_rc_0_1 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none" iDV="False"><NOBR><INPUT tabIndex=-1 onpropertychange='igtbl_chkBoxChange(event,"grdProfile");' type=checkbox></NOBR></TD>
<TD id=grdProfile_rc_0_2 class="ig_2e49b359_r1 GRSHand"><NOBR>*LastName*</NOBR></TD>
<TD id=grdProfile_rc_0_3 class="ig_2e49b359_r1 GRSHand"><NOBR>*FIrstName*</NOBR></TD>
<TD id=grdProfile_rc_0_4 class="ig_2e49b359_r1 GRSHand"><NOBR>*MiddleName*</NOBR></TD>
<TD id=grdProfile_rc_0_5 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>3765545</NOBR></TD>
<TD id=grdProfile_rc_0_6 class="ig_2e49b359_r1 GRSHand"><NOBR>*ID*</NOBR></TD>
<TD id=grdProfile_rc_0_7 class="ig_2e49b359_r1 GRSHand"><NOBR>*ID2*</NOBR></TD>
<TD id=grdProfile_rc_0_8 class="ig_2e49b359_r1 GRSHand"><NOBR>&nbsp;</NOBR></TD>
<TD id=grdProfile_rc_0_9 class="ig_2e49b359_r1 GRSHand"><NOBR>*ID3*</NOBR></TD>
<TD id=grdProfile_rc_0_10 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>*ID2*</NOBR></TD>
<TD id=grdProfile_rc_0_11 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>*Location*</NOBR></TD>
<TD id=grdProfile_rc_0_12 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>PROD</NOBR></TD>
<TD id=grdProfile_rc_0_13 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>0</NOBR></TD>
<TD id=grdProfile_rc_0_14 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>7040</NOBR></TD>
<TD id=grdProfile_rc_0_15 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>&nbsp;</NOBR></TD>
<TD id=grdProfile_rc_0_16 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>&nbsp;</NOBR></TD>
<TD id=grdProfile_rc_0_17 class="ig_2e49b359_r1 GRSHand"><NOBR><A onclick="viewProfile('3765545','*LastName* *FirstName*');" href="javascript:void(0);">View Profile Summary</A></NOBR></TD>
<TD id=grdProfile_rc_0_18 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>&nbsp;</NOBR></TD>
<TD id=grdProfile_rc_0_19 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>&nbsp;</NOBR></TD>
<TD id=grdProfile_rc_0_20 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>&nbsp;</NOBR></TD>
<TD id=grdProfile_rc_0_21 class="ig_2e49b359_r1 GRSHand" style="DISPLAY: none"><NOBR>&nbsp;</NOBR></TD></TR>

任何想法,或者我什至正确使用 dispatchEvent 吗?

Any ideas, or am I even using dispatchEvent properly?

推荐答案

我发现需要发生的是必须触发一些鼠标事件才能继续前进.

I figured out what needed to occur was a few mouse events had to fire to move forward.

我最终在表格中设置了我想要点击的单元格,并使用 fireEvent 来触发所有必须发生的 onmouse* 事件.

I ended up setting the cell in the table that I wanted to click and used fireEvent to fire all of the onmouse* events that had to happen.

     Set objLink = IE1.document.frames("mainParent").document.forms("AgentProfileList").document.getElementById("grdProfile_r_0").document.getElementById("grdProfile_rc_0_2")
 objLink.fireEvent ("onmouseover")
 objLink.fireEvent ("onmousedown")
 objLink.fireEvent ("onmouseup")

这篇关于dispatchEvent - VBA IE 自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆