something i'm trying to accomplish

so i want to make a script that on run will open a certain webpage, this webpage has 3 text fields (space for a name, password, and a number) and it has a button that you click when you’ve filled in all 3 fields

the script that i want will open this webpage, enter the name and password, and based on input from me, will enter the number and then activate the button that you click once those 3 fields are entered

sorry this is kinda vague but i hope someone can help me out

edit: just in case this is relevant (and it probably is) i’m using Safari 4.0.5, and mac os x version 10.5.8

It would help if you’d give the URL of the site, or at least the source code.

eh probably unfortunately it’s a semi confidential thing so i can’t

i’m sure if you could tell me how to do it with something like google i could figure it out from there

WIth some JavaScript you can fill in forms and submit them.

An example for Google:

property SITE_URL : "http://www.google.com"

on run
	tell application "Safari"
		close every document
		-- LOAD URL
		set myDoc to (make new document with properties {URL:SITE_URL})
		
		-- WAIT FOR LOADING COMPLETE
		delay 1
		repeat while (do JavaScript "document.readyState" in document 1) is not "complete"
			delay 0.5
		end repeat
		
		-- FILL IN SEARCH
		do JavaScript "document.getElementsByName('q')[0].value = 'developerief2.site11.com'" in document 1
		do JavaScript "document.forms[0].submit()" in document 1
		
	end tell
end run

To inspect a HTML page in Safari, enable the Develop menu in the preferences.

Application Safari > Menu Bar > Safari > Preferences > Advanced > Show Develop menu in menu bar
Application Safari > Menu Bar > Develop > Show Web Inspector

Hope it helps,
ief2

thank you very much that’s exactly what i was looking for :slight_smile:

Hi

I have applied your script to a website i need to logon to as follows

property SITE_URL : “http://skypark.airmalta.com/

on run
tell application “Safari”
close every document
– LOAD URL
set myDoc to (make new document with properties {URL:SITE_URL})

	-- WAIT FOR LOADING COMPLETE
	delay 1
	repeat while (do JavaScript "document.readyState" in document 1) is not "complete"
		delay 0.5
	end repeat
	
	-- FILL IN SEARCH
	do JavaScript "document.getElementsByName('dnn$ctr721$Login$login_DNN$txtUsername')[0].value = 'aUserName'" in document 1
	do JavaScript "document.getElementsByName('dnn$ctr721$Login$login_DNN$txtPassword')[0].value = 'aPassword'" in document 1
	
	do JavaScript "document.forms[0].submit()" in document 1
	
	(*
	alternative button click ?
	do JavaScript "document.getElementsByName('dnn$ctr721$Login$login_DNN$txtcmdLogin')[0].click" in document 1
	*)
end tell

end run

None of the Javascript commands after – FILL IN SEARCH are working.

What’ wrong?

PS The document.readystate seems to be ‘completing’ a little too early.

Thanks for any help.

Model: iMac
AppleScript: 2.1.2
Browser: Safari 534.10
Operating System: Mac OS X (10.6)

You could also take a look at curl. I have some script’s I post some data to the server with curl so I don’t need to script a browser.