How do I use Applescript to click the Replace button in the Photoshop Save As dialog? I have an Applescript that successfully clicks the Replace button in the InDesign Save As dialog, but the same script doesn't work in Photoshop. It fails on the click command in this section of the script:

tell application "System Events" to tell process activeProcess
    click button "Replace" of sheet 1 of front window
end tell


with this message:

Can't get sheet 1 of window 1 of process "Adobe Photoshop CC 2018": invalid index


Here's what the Accessibility Inspector shows for the Replace button:

I've tried various approaches to identifying the sheet, none of which have worked. Any suggestions?

Just to be thorough, here's what the Save As dialog looks like when the Replace button is available:



Thanks for your help!
This works for me on the latest version of High Sierra and Adobe Photoshop CC 2018...

delay 1
tell application "System Events"
    click UI element "Replace" of sheet 1 of window ¬
        "Save As" of application process "Adobe Photoshop CC 2018"
    delay 0.3
    click UI element "Large file size (Fastest saving)" of window ¬
        "PNG Format Options" of application process "Adobe Photoshop CC 2018"
    delay 0.3
    click UI element "OK" of window "PNG Format Options" of ¬
        application process "Adobe Photoshop CC 2018"
end tell