A complicated script to automate functions in Safari I can navigate a script to control specific "Menu" items... but I can not find information on directing a script to find and click a specific button on a drop down sheet such as the one shown

Im just too inexperienced to know the proper naming and path commands .. any pointers to relevant information is appreciated.

Here is some more information.

Using Automator and Script Editor I made two scripts, saved them as Applications and set them each with a command key.

The result was that I could quickly open and close Safari and have the browser reset each time...
works like a charm until Apple modifies Safari enough where the scripts need to be adjusted for the new path to the same function.

This time the control to reset is the "Clear History" function with I believe also clears the website data as well.
Safari can be set to open in Private mode by default now so that helps a lot for keeping the cache clean

So once the user hits the menu item "Clear History"... instead of a pop up anything... there is a drop down.??..sheet?

I have gotten the script to get as far as that... the script seems to have located the "sheet"... but can not locate the button I want it to click.

What I have so far that gets .. to.. the button that I want clicked:

tell application "System Events"
tell application process "Safari"
    tell menu bar 1 to tell menu bar item "Safari" to tell menu 1 to tell menu item "Clear History…" to click
end tell


end tell

I tried to insert something like:

tell application "System Events" to tell process "Safari" to tell sheet 1 to click (button whose description is "Clear History")


end tell

the error result looks like:

error "Can’t get button whose description = \"Clear History\"." number -1728

Now I’m actually surprise the script got this far as I’m just hacking lines I saw in other scripts that I thought might work.

So basically I just can’t make my script take the jump from controlling a few menu items to getting pointed to some type of drop down and making a button click for me.

Can I extend this to automate UI scripting in Safari?
The following script works for me:

tell application "Safari"
    activate
    close every window
end tell

tell application "System Events"
    tell process "Safari"
        click menu item 6 of menu "safari" of menu bar item "Safari" of menu bar 1
        delay 0.5
        click button 2 of window 1
    end tell
end tell

tell application "Safari"
    make new document
    set the window_width to 1680
    set the window_height to 1575
    set the bounds of window 1 to {0, 22, window_width, 22 + window_height}
end tell