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

查看:354
本文介绍了则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除外)时,无论是onfocus此或onmousedown事件事件被解雇。
和。点击不返回一个错误,但没有做任何事情。

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.

我的code是:

     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天全站免登陆