I am writing an application that gathers information from the user and then fills it out on a webpage. I have no problems getting data into all of the required fields except for the pop up buttons.
The website is: http://www.its.uncc.edu/network/hostdb.html
With the code below, I can click the pop up button and the menu will appear but I keep running into problems getting it to select the menu item.
activate application "Safari"
tell application "System Events"
tell process "Safari"
-- GUI Scripting statements:
tell pop up button 1 of group 61 of UI element 1 of scroll area 1 of group 2 of window "ITS - Network Services - Faculty/Staff Computer & Printer Registration Form"
click
click menu item 1 of menu 1
end tell
end tell
end tell
The error is:
System Events got an error: Can’t get menu 1 of pop up button 1 of group 61 of UI element 1 of scroll area 1 of group 2 of window “ITS - Network Services - Faculty/Staff Computer & Printer Registration Form” of process “Safari”. Invalid index.
I know there is a menu somewhere, but I cannot seem to find it. I’m sure that someone on this site will have an answer because I have found so many solutions here before. Thanks in advance!
Did you ever solve this? I am having the same problem. As a workaround, I can use keystrokes to select the pop-up item I want, but there must be a better way. (mustn’t there?)
The problem (I believe) is that there is no UI menu underneath the popup button. I haven’t been able to find an exact solution. However, you can use javascript to fill in most values on a form. You have to look at the source of your page and find the form name, such as:
then in apple script write:
tell application "Safari"
set theWord to "hello"
set doc to document "ITS - Network Services - Faculty/Staff Computer & Printer Registration Form" -- This is the title of the webpage
log (doc's name)
do JavaScript "document.forms[1]['Ethernet Address'].value = \"" & theWord & "\"" in doc -- Where 'Ethernet Address' is the NAME of the form above
end tell
This is for a text field. However, you can do index scripting for popup buttons. If you would like, I can post some examples of that.
The ONLY problem that I have with this is that if you have to forms with the same exact name, Javascript errors out and does nothing.
Thanks… actually, the form I’m using already has obnoxious JavaScript, so I think trying to set the values in the DOM won’t work for me.
Ah well. keystroke’s actually working fine, other than the odd fact that sending a CR (ASCII character 13) seems to hang up Safari for 5-6 seconds. Weird.