-------------------------------------------------------------------------------------------
set siteUserName to "the-user-name"
set sitePassword to "the-password"
set jsStr to "
document.forms['loginform']['Username'].value = '" & siteUserName & "';
document.forms['loginform']['password'].value = '" & sitePassword & "';
// document.getElementById('#btnSubmit').click();
"
tell application "Safari"
activate
make new document with properties {URL:siteURL}
set bounds of front window to {228, 23, 1542, 1196}
if SAFARI_PAGE_LOADED(20) of me then
tell front document to do _javascript_ jsStr
else
error "Problem loading page in Safari!"
end if
end tell
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on SAFARI_PAGE_LOADED(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do _javascript_ "document.readyState" in document 1) is "complete" then
return true
else if i is the timeout_value then
return false
else
delay 2
end if
end tell
end repeat
return false
end SAFARI_PAGE_LOADED
-------------------------------------------------------------------------------------------