Search code examples
internet-explorercomfoxproie-automation

FoxPro Internet Explorer COM Automation: Clicks not working in IE 10 and Later?


I recently needed to update an old FoxPro legacy application that uses Internet Explorer Automation to drive the content of a Web page by clicking some href links and entering data into a form and submitting.

This used to work just fine but checking on recent versions of Windows with IE 11 (windows 10) and also with IE 10 (Windows 7) I'm seeing that any click event calls on elements have no effect and they fail silently - no error, but also no click.

o = CREATEOBJECT('InternetExplorer.Application')
o.visible = .t.
o.Navigate('http://test.com/ControlBasics.wcsx')

wait window 'page loading...' timeout 1.5

* Target object has no id so navigate DOM to get object reference
oLinks = o.Document.getElementsByTagName('a')
oLink = oLinks.item(0)
oLink.Click()

* o.navigate(oLing.href) && works but not sufficient

o.document.getElementById('txtName').value = 'Rick'
oButton = o.document.getElementById('btnSubmit')
oButton.Click()

In the code above neither of the .click() event triggers have any effect. The assignment to the textbox however works fine, so the page is scripted.

Does anybody know what has changed or what might affect the behavior so that automating event code that previously worked no longer works?


Solution

  • Thanks to the comment of @Noseratio I was able to determine that the problem is specific to the FoxPro COM interface calling into the IE DOM. There are a number of quirks with FoxPro's COM implementation that involve casing and parameter counts. In this case the issue is the latter.

    The way to fix the problem with FoxPro is to call the click method and pass any parameter - it doesn't matter what the value is you just have to pass one.

    So this works:

    oLinks = o.Document.getElementsByTagName('a')
    oLink = oLinks.item(0)
    oLink.Click(.F.)
    

    and

    o.document.getElementById('txtName').value = 'Rick'
    oButton = o.document.getElementById('btnSubmit')
    oButton.Click(.F.)
    

    Notice the .F. parameter in both of those calls to the .Click() function.

    I'm not quite sure what the issue is but my guess is that the default COM signature requires the arguments array and it has to be passed since FoxPro can't deal with optional parameters. By passing the value the COM signature is satisfied and the parameter is just ignored by the receiving function.