1

我对 IE 自动化、javascript 和框架比较陌生。我也不确定我是否有与 IE 自动化弹出的 VBA-Handle Javascript相同的问题。请继续阅读。

先决条件:IE11、VBA for Excel (2010)

所以我试图访问网页对话框的详细信息,您将在其中: 1. 单击一个按钮(以验证给定邮政编码的地址) 2. 一个包含框架的自定义网络对话框打开,要求您从列表中选择该特定邮政编码适用的城市。城市列表不是组合框,而是显示在表格中的锚元素。3. 所以我使用 element.click 单击特定城市,但没有任何反应。

用手动鼠标单击相同的锚元素会触发 javascript 事件 onclick,顺便调用另一个函数。

HTML:

<a class="thisClass" onclick="return thisFunction("1", "arg2", "targetFrame");" href="thisURL#">

和 JavaScript:

function thisFunction( arg1, arg2, targetFrame)  {   
    var thisVar1 = new Object();      
    thisVar1.argument1= arg1;   
    thisVar1.argument2= arg2;   
    window.returnValue = thisVar1 ;      
    window.close();    
}

我的代码:

Set frameEl = IE.Document.getElementById("frameID") 'this is accessing the frame of the webpage dialog popup
Set elem = frameEl.contentDocument
Set anchorElemCollection = elem.getElementsByTagName("a")

For Each anchorElem In anchorElemCollection
    If anchorElem.className Like "thisClass" Then
         If anchorElem.innertext Like aParticularValue Then
               anchorElem.Click
               Exit For
         End If
    End If
Next

anchorElem.Click 部分不起作用。webdialog 弹出窗口没有选择anchorElem,也没有关闭。帮助!我做错了什么?

4

1 回答 1

1

如果您可以确定将传递给arg1arg2的值,请尝试直接运行 javascript 例程。

ie.document.parentWindow.execScript "javascript:thisFunction(some_value1, some_value2, frameEl)
于 2015-05-09T19:14:11.303 回答