When using UI scripting, the relationships between ui objects is not always clear. I'll use Apple's Pages (as it's freely available — I use an untouched 'Essay' document) as an example. Here are two suggestions to explore. If they make sense, you can try similar actions with your own app.
UI Elements command
In a new script…
tell application "Pages"
-- activate -- Not necessary until you want to act upon the window
tell application "System Events" to tell front window of application process "Pages"
UI elements -- generate list of window's ui elements
properties of splitter group 1 -- the first element in the list (branch 1)
UI elements of splitter group 1 -- generate list of first branch
-- entire contents
end tell
end tell
Partial result of command 1
{splitter group 1 of window "Untitled" of application process "Pages" of application "System Events", button 1 of window "Untitled" of application process "Pages" of application "System Events", button 2 of window "Untitled" of application process "Pages" of application "System Events"}
Partial result of command 2
{minimum value:missing value, orientation:missing value, position:{40, 22}}
Partial result of command 3
{scroll area 1 of splitter group 1 of window "Untitled" of application process "Pages" of application "System Events", static text "0 Comments & Changes" of splitter group 1 of window "Untitled" of application process "Pages" of application "System Events", button "Comment" of splitter group 1 of window "Untitled" of application process "Pages" of application "System Events"}
Using ui elements you can work your way through the myriad interface objects in your window. You can also ask for specific properties, e.g. name of every pop up button. Finally, you can get a list of all ui elements with entire contents.
Accessibility Inspector
Using the application Accessibility Inspector, you can inspect the window and discover its elements. This is located inside XCode's app bundle and is also accessible through the XCode > Open Developer Tool menu.
It changes with the version of XCode so there isn't any point in getting too detailed (I'm on Xcode 9) but once it is launched, click on the 'All Processes' drop down button at the top left and it should list the open apps; select Pages from this list.
A couple of things to note: At the bottom is the hierarchy of elements which can help in determining which object to act upon. Each line's bracketed text references the class of object but the text isn't always literal (e.g. your script should use 'window' not 'standard window').
If you use the 'pointer' and then in Pages, click on the empty area at the bottom of the Format inspector, the hierarchy will show a long list of items under (scroll area). Also, there are various ways to interact with an interface object, of which 'click' is but one.
If I insert this code into the script and then select the body text, the script will format the selection as italics (which matches the hierarchy entry 'Regular (pop up button)', with 'Regular' being the selection's existing font format.
tell pop up button 2 of scroll area 2 of splitter group 1 of ¬
window "Untitled" of application process "Pages" of ¬
application "System Events" to perform action "AXPress"
delay 0.5
keystroke "i"
key code 36
Hopefully, utilizing these two approaches may yield some useful results before the onset of ui scripting headache.