1

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?

2
  • Are you actually looking in the right place for the right element? Is the .Click not working or is the correct anchorElem never found and no click is ever performed? Step through your code with F8 or add a debug.print above anchorElem.Click that shows the element was actually found. Commented May 9, 2015 at 19:16
  • I used a breakpoint in the debugger (F12) and yes it did step and performed a click. I just dont understand why it didnt actually clicked the anchor. Commented May 9, 2015 at 23:57

1 Answer 1

1

If you can determine the values that would be passed into arg1 and arg2, try running the javascript routine directly.

ie.document.parentWindow.execScript "javascript:thisFunction(some_value1, some_value2, frameEl)
Sign up to request clarification or add additional context in comments.

5 Comments

I'm gonna try this now. getting back on you later on the results. thanks!
Hi @Jeeped. I have tried the execScript but I have the same problem as before, nothing happens! Yes I am sure of the params passed because I derived the function from the outerHtml of the anchor tag. Also, I cannot put a breakpoint on the exact line to which the code runs on the webdialog popup. Is this normal? Cannot trace it efficiently, step-by-step.
Hi again. I have read at stackoverflow.com/questions/4511874/… that programmatically clicking a link that contains an href is not possible. If any, can there be workarounds with these?
I've had limited success clicking links that execute script. That is why I prefer the .execScript method.
Yeah I also tried doing it that way (execScript) but still to no avail - debugger tells that it clicked the link but nothing happens anyways. Perhaps link.click does not behave the same way as button.click.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.