UI Element Scripting can be accomplished using AppleScript.
I needed a script that would delete my Netflix cookie from Safari and sign me back in.
I used AppleScript to create the following "Reset Cookie" application.
1. Open AppleScript Editor in ~\Applications\Utilities
2. Paste in the following code, then click "Compile" then "Run"
3. Save as an Application (Run Only)
set theWebsite to "netflix"
tell application "Safari" to activate
tell application "System Events" to tell process "Safari"
keystroke "," using command down
tell window 1
click button -3 of tool bar 1
click button "Details…" of group 2 of UI element 2 of row 1 of table 1 of UI element 1 of scroll area 1 of group 1 of group 1
keystroke "a" using command down
click button "Remove" of sheet 1
click button "Done" of sheet 1
keystroke "w" using command down
tell application "Safari" to set the URL of the front document to the "https://signup.netflix.com/Login"
- there is a variable called theWebsite which specifies the name of Cookie I want to look for in Safari's Privacy settings
- the script opens Safari, opens Preferences, and selects the Privacy Tab
- the trick is to target the "Details..." button, which is buried deep in the UI hierarchy
- once that's open, theWebsite value is entered into the search field, the results are selected and removed.
- finally, close the dialog, and tell Safari to open the new webpage (for me, the Netflix sign in page)
- since keychain has my login info, I just tell the script to hit "Return" (the delay gives the page a chance to load, which is important - set that higher for slower connections
Make sure to read this first to make sure your Mac is configured to accept UI Scripting via the Accessability System Preferences and to learn more about UI Scripting.