title: Using Windows Forms to open a browser and call a Javascript function
body: <p>I'm new to this so please bear with me.  I am using a VB.NET (2.0) Windows Forms application.</p>
  
  <p>On Form_Load(), I open up IE browser, which then navigates to a particular URL with a login form.  It passes the u/n and p/w values to this form and gets the button id and calls the click function on it, causing the browser to redirect to the web site as a user.  It then executes a script on that page, which displays a bulk upload control.</p>
  
  <p>I want to be able to get/set the value in the text box on this page.</p>
  
  <p>'-->>> <strong>theTextBox = Nothing</strong>.  After executing the script, the bulk update div is 'created in the page by the script.  If we do a View Source, we can see an element with ID as 'TXT_UPLOAD as below.
  'INPUT type="TEXT" id="TXT_UPLOAD" size="78" onblur="checkFileType(this,this.value, 'true)"
  Here is my code:</p>
  
  <pre><code>Dim IE As New Object
  
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
  
      Dim URL As String = "http://someurl.com/"
  
      Try
  
          IE = CreateObject("InternetExplorer.Application")
          IE.Visible = True
          IE.Navigate("https://someurl.com/Login.aspx?")
  
          Threading.Thread.Sleep(3000)
  
          WaitUntil(IE.Document)
  
  
          IE.Document.getElementById("tb_login").value = "username"
          IE.Document.getElementById("tb_password").value = "password"
  
          Dim theButton
          theButton = IE.Document.getElementById("btn_login")
          theButton.Click()
  
          Threading.Thread.Sleep(5000)
          WaitUntil(IE.Document)
  
          IE.Document.parentWindow.execScript("parent.showApplication('Bulk Update', 712030600,-1,712000000,1);")
  
  
  
          Dim theTextBox
          theTextBox = IE.Document.getElementById("TXT_UPLOAD")
          theTextBox.Focus()
          Debug.Print(theTextBox.value)
          theTextBox.Value = "C:\NV\CV\CLWR_NA_CHG_UPLOAD_2014313.csv"
  
  
         IE.Document.parentWindow.execScript("parent.logOff();")
  
  
      Catch ex As Exception
          MsgBox(ex.ToString)
  
          Threading.Thread.Sleep(5000)
          WaitUntil(IE.Document)
          IE.Document.parentWindow.execScript("parent.logOff();")
  
      End Try
  
      IE = Nothing
  
      'IE.kill()
  
      'IE.Quit()
  
  
      End
  End Sub
  </code></pre>