Auto Website Visit + Form-Fill Script

Hello I’m very green at using AppleScript - but i just put together a simple script
that activates iTunes and Adium when my Bluetooth Phone comes near my iMac.

I’m thrilled that I got it working, but I have a problem.
Before I have access to internet I have to visit a website and enter a login / pass.
(go.i4s.be)
This way, Adium can’t really start and go online when my Bluetooth Phone comes near my iMac.

I would like to know how I can have my iMac automatically start up Safari, go to this website,
enter the login / pass and press the "Login’ button. I don’t even know if that is possible using
AppleScript.

Thanks in advance

I believe it is most certainly scriptable!

This is just an example; I can’t get the login form to come up on the website. So you’ll have to adjust the loginurl field below, as well as change the form values in the script. It should take some experimentation, but it should work in the end!

As an example:

set loginurl to "http://go.i4s.be"
set mylogin to "login"
set mypassword to "password"
tell application "Safari"
	make new document at end of documents
	set URL of document 1 to loginurl
	--This subroutine makes sure the page has finished loading -- it expects the page to finish with the "</html"> tag
	my waitforload()
	--now that the page has loaded, we use Javascript inside Safari to fill in the form and click the submit button!
	do JavaScript "document.forms['formname']['login'].value = '" & mylogin & "'" in document 1
	do JavaScript "document.forms['formname']['password'].value = '" & mypassword & "'" in document 1
	do JavaScript "document.forms[0].elements[3].click()" in document 1
end tell
on waitforload()
	--check if page has loaded
	set loadflag to 0
	repeat until loadflag is 1
		delay 0.5
		tell application "Safari"
			set test_html to source of document 1
		end tell
		try
			set zarg to text ((count of characters in test_html) - 10) thru (count of characters in test_html) of test_html
			if "</html>" is in text ((count of characters in test_html) - 10) thru (count of characters in test_html) of test_html then
				set loadflag to 1
			end if
		end try
	end repeat
end waitforload

If you’re still looking to work on this, let me know and I can help you hammer out the details.