title: Can VBScript automatically log into a website and perform actions via CreateObject(InternetExploerer)?
body: <p>I have an application that I use to play text based games. This application has scripting built into it it so you can create your own plugins. It supports various scripting languages such as JScript, VBScript, and LUA. What I want to do is create a plugin that is capable of logging into an account on a website and then perform various actions, like click a button or submit information. I've done a lot of research into this and I've made some degree of progress, but I keep running into issues. I'm not sure if what I'm trying to accomplish is even possible in the way I'm trying to do it.</p>
  
  <p>So far I've been able to open up the browser and navigate to a page using CreateObject.</p>
  
  <pre><code>function WindowLoad
       IE.Document.getElementByID("user").value = "testacct"
  end function
  Dim IE 
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = 1  
  IE.navigate "http://www.mudconnect.com/SMF/index.php?action=login2"
  Set IE.Window.OnLoad = GetRef("WindowLoad")
  </code></pre>
  
  <p>I'm now trying to figure out a way to fill the input fields with my information. At first I tried to use IE.Document.getElementByID(), however it was displaying this error message: Object required: 'Document.getElementByID(...)'</p>
  
  <p>After doing some research I found out that this could be because it's trying to find the element before the page is loaded. So I decided to try the OnLoad method. However now I can't seem to find any way to reference the "Window." I've tried IE.Window.Onload, IE.Document.Window.Onload, and several other references, but it keeps saying: Object doesn't support this property or method: 'Window'. Anyone have any suggestions for me?</p>
  
  <p>I've also tried:</p>
  
  <pre><code>Do While (IE.Busy) 
  
   Loop
   IE.Document.getElementByID("user").value = "testacct" 
  </code></pre>
  
  <p>I've managed to automatically fill out the form and submit it. My next goal was to be able to navigate while logged in and perform other actions such as voting. I wanted to set up a timer in my client to vote once a day, in case I forget to do it. However, the browsers behavior seems to be erratic once I try to perform another navigate. Here's my updated code:</p>
  
  <pre><code>dim pause
  Dim IE 
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = 1  
  IE.navigate "http://www.mudconnect.com/SMF/index.php?action=login"
  while IE.Busy
     pause = pause + 1
  wend
  world.note pause
  IE.Document.Forms(1).Action = "http://www.mudconnect.com/SMF/index.php?action=login2"
  IE.Document.Forms(1).Elements(0).value = "myUserName"
  IE.Document.Forms(1).Elements(1).value = "myPass"
  IE.Document.Forms(1).Submit
  while IE.Busy
      pause = pause + 1
  wend
  world.note pause
  IE.navigate "http://www.mudconnect.com/cgi-bin/vote_rank.cgi?mud=Legends+of+the+Jedi"
  while IE.Busy
      pause = pause +1
  wend
  world.note pause
  IE.Document.Forms(0).Submit
  </code></pre>
  
  <p>It doesn't appear to be navigating to the new page for some reason. It somehow gets sent somewhere else on the website. Another problem seems to be that it doesn't log me in if I set up a navigate to go somewhere else. I've spent hours reading up on the IE object documentation, but I can't seem to figure out what the issue is. I'm also curious if the IE.Document values get updated whenever you navigate to a new URL?</p>
  
  <p>I solved this part of the problem. The best advice I have for anyone dealing with these particular issues is to pay close attention to the number of forms and elements on a page. View each form as a slot in an array of "forms." Then within each of these forms there is also an array of "elements." A lot of my problems were the result of not identifying the proper "form" or "element" within the array. </p>
  
  <p>However, I still was unable to make this script login AND navigate afterwards. The solution I developed in light of this involved creating a new IE object and having it finish the task for me. It would be more elegant to have the IE object navigate a second time, but I was unable to figure that out. For now I'm going to flag this as solved, since I have found a way to make it work, but I am curious if there is a way to solve the issue I was having.</p>