I am clicking a button on a Safari web page for the +1000th time and suddenly the script fails because the page is testing for JavaScript after the click and I am on a help page. I stopped the script before the click and JavaScript is enabled. I click the button ‘manually’ and no help page. I then substituted the click at location command for the more verbose (I don’t know what its called) command (see below) and it works.
Why is there a difference between the click at and ‘more verbose’ commands? Does Systems Events send a different message for the two commands? Even if it (or something else did) I don’t understand the JavaScript error page appearing when JavaScript is enabled.
Thanks,
Michael
doSomething
on doSomething()
click1({100,200})
clickNext11()
end doSomething
on click1(theClick)
-- this is the general click function
tell application "Safari"
tell application "System Events"
tell process "Safari"
if the length of theClick > 0 then
click at theClick
try
set dummmyVariable to the result as string
on error error_message
my log_event("MDM-TTS ACTION RESULT " & error_message)
end try
end if
end tell
end tell
end tell
end click1
on clickNext11()
-- this is for clicking a next button on page 10
tell application "Safari"
tell application "System Events"
tell process "Safari"
click button 1 of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of group 4 of window 1
try
set dummmyVariable to the result as string
on error error_message
my log_event("MDM-TTS ACTION RESULT " & error_message)
end try
end tell
end tell
end tell
end clickNext11
If by “more verbose” you mean “‘click button 1 of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of group 4 of window 1’ instead of ‘click at {100, 200}’”, then:
The former specifically clicks a button within the hierarchical structure of Safari’s GUI, irrespective of its position on the screen;
The latter clicks at a screen coordinate in the Safari window where you hope the button will be.
If Safari happens to draw the button more than a few pixels away from {100, 200}, the ‘click at’ method will miss it altogether. This may be why the method’s stopped working for you, but without the URL of the Web page and an indication of the button you’re trying to click, I’m afraid the rest of your post doesn’t mean anything.
Thanks Nigel. The geometry was the first thing that came to mind but if I were not clicking the button with the ‘click at’ command then I wouldn’t be going to a page telling me that I needed to turn on JavaScript, right. Something was clicked and unless I just happened to clicked something which went to the help page (telling me to turn on JavaScript) whether or not JavaScript was enabled, I don’t understand why the two different commands behave differently.
The button is being clicked in both cases. ‘click at’ clicks the button and I am sent to the helper page; the hierarchical command takes me to the ‘correct’ next page.