收录日期:2020/10/23 10:46:12 时间:2010-09-07 02:37:13 标签:hyperlink,click,applescript

I am trying to get an Apple Script to click on an item within webpage. This script below works somewhat, I can get it to click different safari tabs or drop down menus, but I cannot get it to click an item within webpage.

In this example, I am trying to get the script to click the "Im feeling Lucky" button from google.. it all works except the click for some reason:

tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
    open location "http://google.com"
    click at {655, 382} -- {from left, from top}
end tell
end tell

The location of the button will likely be different depending on screen size, but anyone have any idea why this is not working?

I'd guess it's because the page hasn't loaded yet. Try adding a delay after you call open location. Using Javascript to click the button would be more flexible, you can do something like this:

tell application "Safari"
  open location "http://google.com"
  delay 1
  do JavaScript "document.forms[0]['btnI'].click()" in front document
end tell