Unable to click/exclude/pass ok on javascript alert appears in webpage using excel VBA

Viewed 146

I am trying to click the download button of website from excel, in the onclick event a javascript has been called and that will retrieve data from the page and convert that to csv format and get downloaded as excel file. Here I can able to click the button however it triggers a popup and macro execution freeze until we click on ”ok” in the webpage , I cannot use send keys and window locate method since macro gets freeze in the onclick action. I tried many approaches but nothing works, I can’t individually replace the onclick function with “” because that alert popup coded at the first line of function where download code is executed so I can’t override it.

Code Behind button:

<input id="Download" onclick="loadDataForDownload();" type="button" value="Download Data Report">

Java script(only few line since its huge one)

 Function loadDataForDownload(){
  alert("This transaction may take few minutes");
  var total ="0.00";

Approaches tried:

With HTMLdoc.parentWindow
  .execScript "window.confirm = function(){return true;};", "JScript"
  .execScript "loadDataForDownload();", "JScript"
End With

using send keys

Application.SendKeys ("{Enter}")

here sendkeys funtion not at all executed because macro execution paused when popup appears in webpage

Screenshot of popup:

enter image description here

Please help me on how to Exclude/ click on the javascript alert popup in ie.

1 Answers

You're overriding window.confirm but the js uses alert which is not the same thing:

With HTMLdoc.parentWindow
   .execScript "window.alert = function(){return true;};", "JScript"
  .execScript "loadDataForDownload();", "JScript"
End With
Related