I am relatively new to IE Automation, javascripts and frames. I also am not sure if I have the same issue as VBA - Handle Javascript pop up with IE automation. Pls read on.
Pre-Requisites: IE11, VBA for Excel (2010)
So I am trying to access the details of a webpage dialog box, wherein you are to: 1. Click a button (to validate address given a zip code) 2. A custom webdialog box containing a frame opens asking you to select from a list of cities in which that particular zip code is applicable. The list of cities isn't a combobox but anchor elements displayed in a table. 3. So I click the particular city using element.click but nothing happens.
Clicking that same anchor element with a manual mouse click triggers the javascript event onclick, which by the way calls another function.
HTML:
<a class="thisClass" onclick="return thisFunction("1", "arg2", "targetFrame");" href="thisURL#">
And the JavaScript:
function thisFunction( arg1, arg2, targetFrame) {
var thisVar1 = new Object();
thisVar1.argument1= arg1;
thisVar1.argument2= arg2;
window.returnValue = thisVar1 ;
window.close();
}
And my code:
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
The anchorElem.Click part isn't working. The webdialog popup window doesn't select the anchorElem, and it doesn't close. HELP! What did I do wrong?