traversing a UI element path - possible?

I’ve located a UI element by searching for it… however it is not the UI element I need. I need the slider that is to the right of this UI element (static text field). This slider does not change position in the hierarchy, it is always slider 3 of scroll area 1 of window X. The window index may change, and the slider doesn’t have anything to uniquely identify it, so this is why I’m searching for the static text UI element.

AppleScript code:
set txt to every UI element of first scroll area of every window whose value is “Electrons”

Result:
static text “Electrons” of scroll area 1 of window 8 of application process “MyApp” of application “System Events”

OK… result is good, it found what I was looking for - the window index.

Is there a way to replace the ‘static text “Electrons”’ with ‘slider 3’ so my ultimate result (what I am after!) would be:
slider 3 of scroll area 1 of window 8 of application process “MyApp” of application “System Events”
?

Thanks!

Hi,

if you can’t filter the value directly, use (again) a repeat loop


.
repeat with w in windows
	if (every UI element of first scroll area of w whose value is "Electrons") is not {} then
		set x to contents of w
		exit repeat
	end if
end repeat
x -- > reference to the window
.

Many thanks for all the help Stefan - it is greatly appreciated!

I tried the code out, and unfortunately, it didn’t work for me. I got the following error:
“System Events got an error: Can’t get scroll area 1 of item 1 of every window of process “MyApp”. Invalid index.”

I tried to play around with it to no avail, I really don’t know where this error is stemming from. It doesn’t seem right tho that the error message mentions “every window” whereas the code appears to me to be going thru one window at a time - is that a good assumption?

try a try block to skip the error messages


.
repeat with w in windows
	try
		if (every UI element of first scroll area of w whose value is "Electrons") is not {} then
			set x to contents of w
			exit repeat
		end if
	end try
end repeat
.

Including the try block made it work - thanks again Stefan!

If only I could get a reference to the UI elements when the window palettes are hidden… sigh.