Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ApolloProg

macrumors newbie
Original poster
Apr 14, 2009
3
0
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:

Code:
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?
 
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.
 
I cleaned it up so people could read it:

Code:
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
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.