【发布时间】:2018-06-13 21:41:42
【问题描述】:
我正在尝试通过 VBA 从我的银行网站自动生成报告。
我成功地访问了该网站并输入了我的用户名和密码,没有任何问题。我已到达通常可以生成报告的页面。 现在我必须模拟点击链接...但我做不到。
这是网站的截图,我必须点击链接的 HTML 代码来生成报告(摘要报告副本)。
这是我需要点击的链接的 HTML 代码:
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false" class="">Summary Report Copy</a>
我试过这行 VBA 代码,但是不行:
IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestatus").FireEvent "onclick"
感谢 VBA,我如何才能点击此“摘要报告副本”?
这里是链接所在网页部分的完整 HTML 代码。也许我没有使用正确的 ID?
<td width="290px">
<span id="irCustomStepOne:headerDataTableId:23:reportNmGrp">
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' & isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false">Summary Report Copy</a>
<a id="irCustomStepOne:headerDataTableId:23:reportnamePrint" href="#" style="float:left;display:none;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if (!onReportLink(\'23\')) return false;','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamePrint\':\'irCustomStepOne:headerDataTableId:23:reportnamePrint\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Print\'},\'_blank\')');return false">Summary Report Copy</a>
<span id="irCustomStepOne:headerDataTableId:23:rpId" style="float:left;display:none;">3368127</span>
</span>
</td>
【问题讨论】:
-
你试过
IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestatus").click吗? -
是的,我试过了,但我得到:运行时错误 '424' Object Required 我不明白,因为这是链接的 ID...
-
在导航到网站后尝试等待几秒钟,看起来文档没有完全加载。在链接点击行上方添加:
Application.Wait (Now + TimeValue("0:00:08")) -
同样的事情,我已经放了这行代码以确保所有内容都已加载。很抱歉浪费您的时间,我之前应该告诉过您的 ;-) 还有其他触发此链接的想法吗?
标签: javascript html vba excel