title: How to code vba with reference to selenium for clicking the close button of the pop up in edge browser that is modal based
body: <p>I would like to create an excel macro to automate the data upload into government site and then retrieve a QR code png in return to put into the worksheet after data are swiftly processed from their end. I'm a newbie here.</p>
  <p>I am stuck in the early stage where I could not state the correct element for the close button or the &quot;tutup pengumuman&quot; button in the pop-up overlay. The website will refresh every 60s. I have tried the below but to no avail:</p>
  <p>Hopefully there is someone who can advise on my problem here. Thanks!</p>
  <pre><code>    Public Sub selenium()
          Dim bot As New WebDriver
          bot.Start &quot;edge&quot;, &quot;https://simka-outbreak.moh.gov.my/outbreak/index.php&quot;
          bot.Get &quot;/&quot;
          bot.Window.Maximize
          bot.Wait 100000
          bot.FindElementById(&quot;myModal2&quot;).Click
          bot.FindElementByClass(&quot;close&quot;).Click
          bot.FindElementByXPath(&quot;//*[@id='myModal2']/div/div/div[1]/button&quot;).Click
          bot.FindElementByClass(&quot;btn btn-primary&quot;).Click
          bot.FindElementByXPath(&quot;//*[@id='myModal2']/div/div/div[2]/center/b/button&quot;).Click
          bot.FindElementById(&quot;username&quot;).SendKeys (&quot;username&quot;)
          bot.FindElementById(&quot;password&quot;).SendKeys (&quot;password&quot;)
          bot.FindElementById(&quot;submitBtn&quot;).Click
          bot.Wait 1000000
      End Sub
  </code></pre>
  <p>html as below:</p>
  <pre><code>&lt;div id=&quot;myModal2&quot; class=&quot;modal fade&quot;&gt;
      &lt;div class=&quot;modal-dialog&quot;&gt;
          &lt;div class=&quot;modal-content&quot;&gt;
              &lt;div class=&quot;modal-header&quot;&gt;
                  &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/button&gt;
                  &lt;h4 class=&quot;modal-title&quot;&gt;Pengumuman Penting&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class=&quot;modal-body&quot;&gt;
                  &lt;p&gt;
                  
                  &lt;b&gt;&lt;font color=blue&gt;PENUTUPAN KHIDMAT BANTUAN PENGGUNA MELALUI WHATSAPP&lt;/font&gt;&lt;/b&gt;
  &lt;br&gt;&lt;br&gt;
  Tuan/Puan Yang Dihormati
  &lt;br&gt;&lt;br&gt;
  Merujuk kepada perkara diatas, &lt;font color=red&gt;&lt;b&gt;khidmat bantuan pengguna melalui Whatsapp ditutup buat sementara waktu&lt;/b&gt;&lt;/font&gt;.&lt;br&gt;&lt;br&gt;Sila emel ke it.mkak@moh.gov.my atau hubungi 03-6126-1200 (Hari Isnin hingga Jumaat dari jam 9pagi hingga 5petang sahaja) untuk sebarang bantuan.&lt;br&gt;&lt;br&gt;Terima kasih diatas kesabaran pihak tuan/puan.&lt;b&gt;&lt;br&gt;&lt;br&gt;
  
  
  
  
  &lt;br&gt; 
  
  
  &lt;!--
  &lt;b&gt;&lt;font color=blue&gt;HEBAHAN KEMASKINI PEMBOLEHUBAH SIMKA OUTBREAK&lt;/font&gt;&lt;/b&gt;
  &lt;br&gt;&lt;br&gt;
  Tuan/Puan Yang Dihormati
  &lt;br&gt;&lt;br&gt;
  Mohon muat turun kemaskini terbaru bertarikh &lt;font color=red&gt;&lt;b&gt;18hb Mei 2021&lt;/b&gt;&lt;/font&gt; untuk maklumat Pemboleh Ubah SIMKA Outbreak&lt;b&gt;&lt;br&gt;&lt;br&gt;
  
  Sila muat turun dokumen berkaitan dengan mengklik link &lt;a href=&quot;https://simka-outbreak.moh.gov.my/HebahanKemaskiniPembolehUbahSimka.pdf&quot; target=&quot;_blank&quot;&gt;DI SINI&lt;/a&gt;&lt;/b&gt;.&lt;br&gt;&lt;br&gt;
  
  &lt;br&gt;&lt;br&gt;
  
  &lt;br&gt;--&gt;
  
  
                  &lt;/p&gt;&lt;center&gt;
                  &lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; data-dismiss=&quot;modal&quot;&gt;Tutup Pengumuman&lt;/button&gt;
              &lt;/center&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt; 
  
  </code></pre>