I want to make an Apple script to evaluate data
Hi everyone,
I want to make an apple script to evaluate data taken from a website where login is required. I am already having trouble with the first steps...
First I had something, you'll probably laugh about:
tell application "Safari"
open location "http://c108-013.cloud.gwdg.de/accounts/login/?next=/sabo/"
activate
tell application "System Events"
keystroke "test_usr"
delay 3
keystroke return
keystroke "test_pw"
delay 3
keystroke return
end tell
tell application "Safari"
open location "http://c108-013.cloud.gwdg.de/sabo/overview/1"
end tell
end tell
it worked, but it was very unreliable and in the end it messed up all the time.
So now, I have something which is supposed to be neater, but I cannot make it work:
set user_name to "test_usr"
set user_password to "test_pw"
tell application "Safari"
activate
open location "http://c108-013.cloud.gwdg.de/accounts/login/?next=/sabo/"
end tell
#^^this works
to inputByName(theName, theValue)
tell application "Safari"
tell tab 1 of window 1
do JavaScript "
document.getElementByName('username').value=user_name;
document.getElementByName('password').value=user_password;
document.forms[0].submit()
" in document 1
end tell
end tell
end inputByName
#^^nothing happens here
tell application "Safari"
open location "http://c108-013.cloud.gwdg.de/sabo/overview/1"
end tell
#^^this works
Extra infos: The reason why I open a tab, login and then open another one is, that I actually need to navigate from the homepage (after login) through a button to another site. It is not so elegant this way, but it works after I'm logged in.
Maybe I make mistakes in reading the source code to get the elements:
Since I can't find a ID or class, I'm trying to cope with the name of the element...
I have no idea about Javascript or Applescript or any other coding, its probably a stupid mistake...
Happy about any help!
[Re-Titled by Moderator]