title: Unable to make my script stop printing wrong result
body: <p>I've created a script in vba using IE to fill in few inputs in a webpage in order to reach a new page to check for some items availability based on inputting some values in an inputbox.</p>
  
  <p>To walk you through: what the script is currently doing:</p>
  
  <ol>
  <li>Select <code>Buy Bricks</code> from landing page</li>
  <li>Enter age <code>30</code> and country <code>United Kingdom</code> and then click on <code>submit</code> button</li>
  <li>On the next page, enter the unique identification number for the Lego piece in the <code>Element/design</code> number box to populate result. </li>
  </ol>
  
  <blockquote>
    <p>My script can satisfy all the requirements stated above. However, when I try with three different numbers, as in <code>4219725</code>,<code>765467</code> and <code>230223</code> I can see that the one in the middle <code>765467</code> doesn't populate any result but It prints the result of it's earlier number.</p>
  </blockquote>
  
  <p>All the three numbers have been used in a <code>for loop</code> within my script below.</p>
  
  <p><strong><em>How can I make my script print nothing when there is no result instead of printing wrong result?</em></strong></p>
  
  <p><a href="https://www.lego.com/en-gb/service/replacementparts" rel="nofollow noreferrer">Site address</a></p>
  
  <p>My script so far: (could not kick out hardcoded delay)</p>
  
  <pre><code>Sub GetDetails()
      Const timeOut = 10
      Dim IE As New InternetExplorer, Html As HTMLDocument
      Dim elem As Object, post As Object, inputNum As Variant
      Dim ageInput As Object, itm As Object, T As Date
  
      With IE
          .Visible = True
          .navigate "https://www.lego.com/en-gb/service/replacementparts"
          While .Busy Or .readyState &lt; 4: DoEvents: Wend
          Set Html = .document
          Dim event_onChange As Object
          Set event_onChange = .document.createEvent("HTMLEvents")
          event_onChange.initEvent "change", True, False
  
          Html.querySelectorAll(".arrow-list-info")(2).Click
  
          Do: Set ageInput = Html.querySelector("input[id*='How old']"): DoEvents: Loop While ageInput Is Nothing
          ageInput.innerText = 30
          Html.querySelector("[label='United Kingdom").Selected = True
          Html.querySelector("select").dispatchEvent event_onChange
          Html.querySelector("[ng-click='startFlow()'").Click
  
          While .Busy Or .readyState &lt; 4: DoEvents: Wend
          Set Html = .document
  
          For Each inputNum In [{4219725,765467,230223}]
              T = Timer
              Do: Set post = Html.querySelector("[placeholder='Element/design number']"): DoEvents: Loop While post Is Nothing
              post.ScrollIntoView
              post.Focus
              post.innerText = inputNum
              Html.querySelector("button[ng-click='searchItemNumber()']").Click
  
              'Can't kick out this hardcoded delay
              Application.Wait Now + TimeValue("00:00:02")
  
              Do
                  Set elem = Html.querySelector("div.list-item")
                  If Timer - T &gt; timeOut Then Exit Do
                  DoEvents
              Loop While elem Is Nothing
  
              Set itm = Html.querySelector("h6.title")
              If Not itm Is Nothing Then
                  Debug.Print itm.innerText
              Else:
                  Debug.Print "Found Nothing"
              End If
          Next inputNum
          Stop
      End With
  End Sub
  </code></pre>