title: How do I interact with this Internet Explorer Dropdown ComboBox Navigation using VBA Macro?
body: <p>I am having difficulty trying to automate a dropdown comboBox in internet explorer using an Excel Macro. Note that I am very new to VBA language and web scraping.</p>
  
  <p>The code I am using unsuccessfully is:</p>
  
  <pre><code>'Change Posting Period
  
  Dim posting As Object
  Set posting = ie.Document.getElementById("inpt_postingperiod2")
  posting.Value = ActiveWorkbook.Sheets("RMA").Range("C5").Value
  
  'The value in this cell C5 in this instance is: Aug 2019
  </code></pre>
  
  <p>In internet explorer, this code will change the text that is displayed in the dropdown box but when I later submit the page, the underlying value was never really changed.</p>
  
  <p>I tried adding the fireevents to the code such as:</p>
  
  <pre><code>posting.fireevent ("onfocus")
  posting.fireevent ("onkeydown")
  </code></pre>
  
  <p>with no success</p>
  
  <p>The script related to the dropdown is:</p>
  
  <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;input name="inpt_postingperiod" title="Sep 2019" class="dropdownInput textbox uir-field-active" id="inpt_postingperiod2" role="combobox" aria-labelledby="postingperiod_fs_lbl" style="width: 280px; background-color: rgb(255, 255, 255);" contenteditable="false" onkeydown="getDropdown(this).handleKeydown(event);" onkeypress="getDropdown(this).handleKeypress(event);" onfocus="getDropdown(this).handleOnFocus(event);" onblur="getDropdown(this).handleOnBlur(event);" type="text" value="Sep 2019" autocomplete="off"&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And the script for the dropdown option items:</p>
  
  <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;div class="ns-dropdown" style="display: none;" data-name="postingperiod" data-settings='{"flags":-2147483520,"width":280,"minWidth":280,"mandatory":true}' data-default-option="4" data-options='[{"value":"127","text":"May 2019"},{"value":"128","text":"Jun 2019"},{"value":"129","text":"Jul 2019"},{"value":"131","text":"Aug 2019"},{"value":"132","text":"Sep 2019"},{"value":"133","text":"Oct 2019"},{"value":"138","text":"Nov 2019"},{"value":"139","text":"Dec 2019"},{"value":"140","text":"Jan 2020"},{"value":"142","text":"Feb 2020"},{"value":"143","text":"Mar 2020"},{"value":"144","text":"Apr 2020"}]' data-initialized="T"&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Note that the Excel value of Aug 2019 should be selected from the dropdown options list. Thus, in order to automate this, I cannot use the value/index number since this will change in the future; I need to match the excel cell value of MMM YYYY to the MMM YYYY in the dropdown list (in this example Aug 2019).</p>
  
  <p>Thank you for all the help!</p>
  
  <p>Full code should be:</p>
  
  <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;tr&gt;
  
    &lt;td&gt;
  
  &lt;div class="uir-field-wrapper" data-field-type="select"&gt;&lt;span id="postingperiod_fs_lbl_uir_label" class="smallgraytextnolink uir-label "&gt;&lt;span id="postingperiod_fs_lbl" class="labelSpanEdit smallgraytextnolink" style=""&gt;
  
  &lt;a tabindex="-1" title="What's this?" href="javascript:void(&amp;quot;help&amp;quot;)" style="cursor:help" onclick="return nlFieldHelp('Field Help','postingperiod', 'TRAN_CUSTCRED_postingperiod_NA', this, 'EDIT_TRAN_CUSTCRED', '3905005', 'custcred', 136, 'creditmemo', 'T', '', 'Credit+Memo', 'APP:FORMLABEL:POSTING_PERIOD', '')" class="smallgraytextnolink" onmouseover="this.className='smallgraytext'; return true;" onmouseout="this.className='smallgraytextnolink'; "&gt;Posting Period&lt;/a&gt;
  &lt;img class="required_icon" title="Required Field" alt="Required Field" src="/images/chiles/pageTitle/required.png"&gt;&lt;label class="uir-required-icon"&gt;*&lt;/label&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="uir-field"&gt;
          &lt;span id="postingperiod_fs" data-fieldtype="select" class="nldropdown" style="white-space:nowrap;" data-helperbutton-count="0"&gt;&lt;div class="uir-select-input-container"&gt;&lt;input name="inpt_postingperiod" type="text" value="Sep 2019" class="dropdownInput textbox" onkeydown="getDropdown(this).handleKeydown(event);" onkeypress="getDropdown(this).handleKeypress(event);" onfocus="getDropdown(this).handleOnFocus(event);" onblur="getDropdown(this).handleOnBlur(event);" aria-labelledby="postingperiod_fs_lbl" autocomplete="off" contenteditable="false" role="combobox" id="inpt_postingperiod2" title="Sep 2019" style="width: 280px; background-color: rgb(255, 255, 255);"&gt;&lt;span class="ddarrowSpan"&gt;
   &lt;img src="/uirefresh/img/field/dropdown.png" height="20" width="20" class="i_dropdownarrow" alt="More Options" id="inpt_postingperiod2_arrow"&gt;
  &lt;/span&gt;&lt;/div&gt;
  
  &lt;div class="ns-dropdown" data-name="postingperiod" data-initialized="T" data-options="[{&amp;quot;value&amp;quot;:&amp;quot;127&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;May 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;128&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Jun 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;129&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Jul 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;131&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Aug 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;132&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Sep 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;133&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Oct 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;138&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Nov 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;139&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Dec 2019&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;140&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Jan 2020&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;142&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Feb 2020&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;143&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Mar 2020&amp;quot;},{&amp;quot;value&amp;quot;:&amp;quot;144&amp;quot;,&amp;quot;text&amp;quot;:&amp;quot;Apr 2020&amp;quot;}]" data-default-option="4" data-settings="{&amp;quot;flags&amp;quot;:-2147483520,&amp;quot;width&amp;quot;:280,&amp;quot;minWidth&amp;quot;:280,&amp;quot;mandatory&amp;quot;:true}" style="display: none; "&gt;
  &lt;/div&gt;
  
  
  
  
  
  &lt;input name="postingperiod" type="hidden" class="nldropdown" value="132" onchange="this.isvalid=(nlapiValidateField(null,'postingperiod'));if (!this.isvalid) return false;if(!this.noslaving) { setWindowChanged(window, true); }if (Syncpostingperiod(true,null,null,null,null,null) == false) return false;if (getEventTarget(event)==this)this.focus();var kPeriod = nlapiGetFieldValue('postingperiod');
  if (nlapiGetFieldValue('ppsetbyuser') != 'T' || kPeriod != nlapiGetFieldValue('ppsetbyuservalue')) {
   if ( nlapiGetField('postingperiod').noSlaving() || nlapiGetFieldValue('ppsetbyuser') == 'S' ) {
  var kPeriod = nlapiGetFieldValue('postingperiod');
  if (kPeriod &amp;amp;&amp;amp; typeof pp_ss !== 'undefined' &amp;amp;&amp;amp; pp_ss[1132] !== undefined) {
   var iPeriod = + kPeriod + 1000;
   var bUseCurrent = (pp_ss[iPeriod] === undefined)
   if (!bUseCurrent) {
   var td = stringtodate(nlapiGetFieldValue('trandate'));
   var pp_s = stringtodate(pp_ss[iPeriod]);
   var pp_e = stringtodate(pp_es[iPeriod]);
   var cur_s = stringtodate(pp_es[1132]);
    bUseCurrent = !(pp_s &lt;= td &amp;amp;&amp;amp; pp_e &gt;= td) &amp;amp;&amp;amp; cur_s &gt; pp_s;
   }
   if (bUseCurrent)
    nlapiSetFieldValue('postingperiod', 132, false);
  }
  nlapiSetFieldValue('ppsetbyuser', 'F', false);
  nlapiSetFieldValue('ppsetbyuservalue', '', false);
   } else if (kPeriod) {
  nlapiSetFieldValue('ppsetbyuser', 'T', false);
  nlapiSetFieldValue('ppsetbyuservalue', nlapiGetFieldValue('postingperiod'), false);
   }
  }
  ;nlapiFieldChanged(null,'postingperiod');" id="hddn_postingperiod2"&gt;
  
  &lt;input type="hidden" value="4" id="indx_postingperiod2"&gt;
  
  &lt;script type="text/javascript"&gt;
      (function () {
          var win = (window.parentAccesible != false &amp;&amp; parent.initializeDropdowns) ? parent : window;
          win.initializeDropdowns(win.NS.jQuery(document));
      }())
  &lt;/script&gt;&lt;span class="field_widget_helper_pos effectStatic"&gt;&lt;/span&gt;&lt;/span&gt;
  &lt;/span&gt;
  &lt;/div&gt;
    &lt;/td&gt;
  
      &lt;/tr&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Note, the dropdown options do not display because they are generated from a password protected website but the options are just dates in MMM YYYY format</p>
  
  <p>I also tried:</p>
  
  <pre><code>Dim posting As Object
  Set posting = ie.document.querySelector("#inpt_postingperiod2")
  posting.Value = ActiveWorkbook.Sheets("RMA").Range("C5").Value
  posting.fireevent ("onchange")
  </code></pre>
  
  <p>with no success: I don't think changing the text value props the dropdown and makes a selection. You can see this when hovering over the dropdown.  Even though it says Aug 2019 it is actually Sept 2019:</p>
  
  <p><a href="https://i.stack.imgur.com/GZG5m.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>Image showing dropdown not selected correctly before submission</p>