title: simulating mouse click to download file from IE browser
body: <p>Dashboard sample:</p>
  <p><img src="https://i.stack.imgur.com/pDUVE.jpg" alt="Dashboard sample" /></p>
  <p>I'm trying to simulate a mouse click on a form on a browser to download report.
  I got stuck immediately when targeting the download link/image.
  I also realize the form is using a post method to retrieve the file, so I'm not sure if just simulating a mouseclick on the link/image is sufficient.</p>
  <pre><code>Sub TestDownload()
      Dim elements As Object, element As Object, count As Long
      Dim IE As Object
      Set IE = CreateObject(&quot;InternetExplorer.Application&quot;)
      
      IE.Visible = True
      IE.Navigate &quot;https://something.com/Dashboard&quot;
      
      ' Wait while IE loading...
          Do While IE.Busy
              Application.Wait DateAdd(&quot;s&quot;, 1, Now)
          Loop
          
      count = 0
      Set elements = objIE.document.getElementsByTagName(&quot;a&quot;)
      
      For Each element In elements
          If element.className = &quot;ExportCurrentExtInt&quot; Then
                     element.Click
          End If
      Next
      
  End Sub
  </code></pre>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form id="myForm" name="myForm" method="post" action="/NSPortal/Dashboards/CEPDashboard"&gt;
      &lt;input type="hidden" name="ReportDate" id="ReportDate" value="4/1/2020" /&gt;
      &lt;input type="hidden" name="Domain" id="Domain" value="" /&gt;
      **&lt;input type="hidden" name="SubmitButton" id="SubmitButton" value="jqGridExportToExcel"&gt; *--&gt; the value appears when i click on the link to initiate the download*
      &lt;input type="hidden" name="ExportTarget" id="ExportTarget" value="ExportCurrentExtInt"&gt;**
      &lt;input type="hidden" name="ExportFilterField" id="ExportFilterField" value="" /&gt;
      &lt;input type="hidden" name="ExportFilterValue" id="ExportFilterValue" value="" /&gt;
      &lt;input type="hidden" name="OpenTab" id="OpenTab" value=""/&gt;
      &lt;table id='tableDateSelection' border='0' cellpadding='0' cellspacing='0' width='100%' style='border-color: #F5F5F5'&gt;
  
  &lt;/select&gt;
  
                                  &lt;tr&gt;
                                      &lt;td class="RoundedPanelCenterLeft"&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;a id="ExportCurrentExtInt"&gt;Export Current EXT-INT Interfaces &amp;nbsp;&lt;img style="vertical-align:top" alt="Export current EXT-INT Interfaces to Excel" src="/NSPortal/Content/Images/excel.gif" border="0"/&gt;&lt;/a&gt;&lt;/td&gt;
                                      &lt;td class="RoundedPanelCenterRight"&gt;&lt;/td&gt;
                                  &lt;/tr&gt;
  
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I tried to use Element ID but it's throwing me an error.</p>
  <pre><code>Do
  DoEvents
  Loop Until IE.readyState = READYSTATE_COMPLETE
  
  objIE.document.getElementById(&quot;ExportTarget&quot;).Click
  
  End Sub
  </code></pre>