PDA

View Full Version : Apple Script Help- Clicking somewhere in Safari




ApolloProg
Apr 14, 2009, 07:56 PM
Hey.
So I have an apple script question,
How do I get Apple Script to click somewhere in safari via source code of a page?
I'm trying to get Apple script to tell safari to click a button.
This is pretty much what I'm trying to do:

tell application "Safari"
activate

do JavaScript "window.open('http://www.WebPageHere.com')" in document 1
end tell

tell application "System Events"
tell process "Safari"
--Whatever Goes Here To Make Safari Click On The Button
end tell
end tell
Any ideas?



andmr
Apr 17, 2009, 09:25 AM
Try this, perhaps:

tell application "Safari"
activate
do JavaScript "window.open('http://www.WebPageHere.com')" in document 1
delay 8 -- need to allow enough time for the web page to load; adjust as necessary
end tell
tell application "System Events"
tell process "Safari"
repeat x times -- where x = the number of times it takes to reach the button using the tab key
keystroke tab
end repeat
keystroke return -- performs the press action
end tell
end tell

Good luck.

LtRammstein
Apr 17, 2009, 09:27 PM
I cleaned it up so people could read it:


tell application "Safari"
activate
do JavaScript "window.open('http://www.WebPageHere.com')" in document 1
delay 8 -- need to allow enough time for the web page to load; adjust as necessary
end tell

tell application "System Events"
tell process "Safari"
repeat x times -- where x = the number of times it takes to reach the button using the tab key
keystroke tab
end repeat
keystroke return -- performs the press action
end tell
end tell

ApolloProg
May 1, 2009, 07:17 PM
I need it to click a button though. Not enter text.

andmr
May 2, 2009, 06:21 AM
I need it to click a button though. Not enter text.

The script is designed to click a button.

If you find that pressing the Tab key repeatedly doesn't bring focus to the desired button, make sure that under Safari Preferences > Advanced > "Press Tab to highlight each item on a webpage..." is checked, and that under System Preferences > Keyboard & Mouse > Keyboard Shortcuts > Full keyboard access, "All Controls" is selected.

Good luck.