问题
the problem I'm having is making me sick. I'm working over an applescript that throws action to fill form. I think I'm having an issue while getting it to wait until the site is loaded in 100%. The script activates the site but doesn't fill the forms. Please navigate me and help to work out this lazy script:
tell application "Safari"
set loginurl to "http://www.dogomania.pl/forum/register.php"
set mylogin to "worker100"
set mypassword to "blackie698"
tell application "Safari"
make new document at end of documents
set URL of document 1 to loginurl
delay 4
do JavaScript "document.forms['regusername']['username'].value = '" & mylogin & "'" in document 1
do JavaScript "document.forms['password']['password'].value = '" & mypassword & "'" in document 1
end tell
end tell
回答1:
Looks like you simply have the form id/hierarchy wrong. This worked for me:
tell application "Safari"
do JavaScript "document.forms['registerform']['regusername'].value = '" & mylogin & "'" in document 1
end tell
... and use the same form id for the 'password' field and other fields.
or you can do this, too, and only worry about the specific element id:
tell application "Safari"
do JavaScript "document.getElementById('regusername').value = '" & mylogin & "'" in document 1
end tell
来源:https://stackoverflow.com/questions/22615180/making-applescript-fill-form