views:

281

answers:

3

How to automate the submission of html form, with random text values using vbscript?

A: 

You can use the "Microsoft.XMLHTTP" to automate the form submittal. Please see below:

Set xml = Server.CreateObject("Microsoft.XMLHTTP")

' Notice the two changes in the next two lines:
xml.Open "POST", "http://www.imdb.com/Find", False
xml.Send "select=All&for=The Usual Suspects"

wscript.echo xml.responseText

Or take a look at these great posts:

http://www.4guysfromrolla.com/webtech/110100-1.2.shtml

http://www.4guysfromrolla.com/webtech/110100-1.shtml

http://support.microsoft.com/kb/290591

mrTomahawk
This would be correct in the case of ASP. But this does not work automation of form submission from a normal (*.vbs) file.
Smart Pandian
I don't know what you mean. The example I showed has nothing to do with server side code being ASP, it could CGI, PHP, hell even Ruby all that matters is that you submit the values expected by the server side code during a form submit. You also asked how it could be done using VBScript, which is what my example(s) are showing. Can you revise your to maybe emphasize what problem your trying to overcome?
mrTomahawk
I guess Smart Pandian means that `Server` is ASP-specific object, which is not available in Windows Script Host (he says he uses *.vbs files, that is, runs code as a Windows script, not web script). In this case, the first statement should be changed to `Set xml = CreateObject("Microsoft.XMLHTTP")`.
Helen
A: 

You may want to use Selenium (http://seleniumhq.org/) or Waitr (http://wtr.rubyforge.org/) as they will allow you better control and are built to do what you are looking for.

Josh
A: 
<html>
    <form action='http://127.0.0.1/file.php' method='POST' id=1>
        <input type=hidden name="var" value="val">
        <input type=submit>
    </form>
</html>
<script>
    document.getElementById(1).submit();
</script>
Rook