How to click button with applescript using UI Element Inspector I am new to applescript. I am trying to open a webpage, and click a button on that webpage. 

here is my script:

tell application "Safari" to activate
tell application "System Events"
    tell application "System Events" to open location "https://itunes.apple.com/us/app/ibooks/id364709193?mt=8"
    click button "View In iTunes" of window "iBooks for iPhone, iPod touch, and iPad on the iTunes App Store"
end tell


here is my info gathered from inspector:

&lt;AXApplication: “Safari”&gt;
 &lt;AXWindow: “iBooks for iPhone, iPod touch, and iPad on the iTunes App Store”&gt;
  &lt;AXGroup&gt;
   &lt;AXGroup&gt;
    &lt;AXGroup&gt;
     &lt;AXScrollArea: “”&gt;
      &lt;AXWebArea: “”&gt;
       &lt;AXLink: “View In iTunes
”&gt;
        &lt;AXGroup: “”&gt;

Attributes:
   AXRole:  “AXGroup”
   AXSubrole:  “(null)”
   AXRoleDescription:  “group”
   AXChildren:  “&lt;array of size 1&gt;”
   AXHelp:  “”
   AXParent:  “&lt;AXLink: “View In iTunes
”&gt;”
   AXPosition:  “x=-9566 y=574”
   AXSize:  “w=10105 h=23”
   AXTitle:  “”
   AXDescription:  “”
   AXValue:  “”
   AXFocused:  “0”
   AXEnabled:  “1”
   AXWindow:  “&lt;AXWindow: “iBooks for iPhone, iPod touch, and iPad on the iTunes App Store”&gt;”
   AXSelectedTextMarkerRange (W):  “(null)”
   AXStartTextMarker:  “&lt;AXTextMarker 0x100151f70 [0x7fff77fa1110]&gt;{length = 24, bytes = 0x070000000000000078140319010000000000000001000000}”
   AXEndTextMarker:  “&lt;AXTextMarker 0x100177c50 [0x7fff77fa1110]&gt;{length = 24, bytes = 0x9a00000000000000c09de015010000000e00000001000000}”
   AXVisited:  “0”
   AXLinkedUIElements:  “(null)”
   AXSelected:  “0”
   AXBlockQuoteLevel:  “0”
   AXTopLevelUIElement:  “&lt;AXWindow: “iBooks for iPhone, iPod touch, and iPad on the iTunes App Store”&gt;”
   AXTitleUIElement:  “(null)”

Actions:
   AXPress - press
   AXShowMenu - show menu


How do I click the "View in iTunes" button?
This is the easiest way...

tell application "Safari"
    if not (exists document 1) then reopen
    activate
    set URL of document 1 to "https://itunes.apple.com/us/app/ibooks/id364709193"
    delay 3
    do JavaScript "document.getElementsByClassName('lockup product application')[0].childNodes[3].onclick()" in document 1
end tell