Check Items in Drop Down List on Web Page

Hi I have a routine that steps through a drop down list and selects the last one. My problem is my list will grow and I cannot work out how to check how many items are in the list or what each one is.

The following script works at present but is not what I really need. It is set to step down seven times because that his one more than is presently in the drop down list. However if I could get the value of each item in the list I could exit the repeat when it found what it needed. Or as at present what I am looking for is the last item if I could set the repeat to the number of items in the list that would work.


tell application "System Events"
	tell process "Safari"
		click pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio"
		--It will be the last one step through each it should only need 6 repeats but it can stall
		repeat 7 times
			key code 125 --Step down
		end repeat
		key code 36 --Select last Item
	end tell
end tell


Thanks for any suggestions

Peter

Model: MacBook Pro
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14

Have a look at UI browser.

https://pfiddlesoft.com/uibrowser/
There may be something that you can wueeynto her
The number of element in the pop down menu.

Have a look for something like menu items count

Hi Thanks for the reply

I am using UI which is how I have got to this point however I have tried I think every possibility in there library for a drop down box without any luck. I can return the value of the 1st item in the list but not past that. The following code returns the 1st name in the list but if I change “Item 1” to “item 2” I get an invalid index error so I assume I some how need to get the correct index.


tell application "System Events"
	tell process "Safari"
		click pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio"
				
		--################# 
		--"DoD" is one of the names in the drop down box but this approach does not work
		(*tell pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio"
			click (first button where its accessibility description = "DoD")
		end tell*)
		--#########################
		key code 125
		set PORTX to the value of item 1 of ((pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio"))
		
	end tell
end tell

Thanks Peter

You may try :

tell application "System Events"
	tell process "Safari"
		set frontmost to true
		tell pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio"
			set itsName to its name -- get the name of the pop up
			set itsValue to its value -- get the name of the selected menu item
			click it
			tell menu 1
				set menuItems to name of menu items
				-- click menu item (one of the strings in menuItems)
			end tell
		end tell
	end tell
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 4 janvier 2020 07:17:12

Once again thanks very much, the help form this community has been great.
Unfortunately your suggestion did not get me far. The web site is ADFVN but one has to have an account to login, although its free at its basic level which is what I am using.

Logging events shows missing value for “itsName” and “All Portfolios” for “its value”. All Portfolios is the 1st name of the pop up button list

And the name in the tell block results in this error

error “System Events got an error: Can’t get menu 1 of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio" of process "Safari". Invalid index.” number -1719 from menu 1 of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”

Thank you again, I guess I am missing something very simple.

Peter

I rebuilt the script so that it trigger the UI element in a more practical order.


(*
tell application "System Events"
tell process "Safari"
set frontmost to true
tell pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio"
set itsName to its name -- get the name of the pop up
set itsValue to its value -- get the name of the selected menu item
click it
tell menu 1
set menuItems to name of menu items
-- click menu item (one of the strings in menuItems)
end tell
end tell
end tell
end tell
*)

tell application "System Events"
	tell process "Safari"
		set frontmost to true
		name of window 1 --> "Portfolio"
		tell window "Portfolio"
			log "in window" --> "in window"
			class of UI elements --> { …, splitter group, … }
			tell splitter group 1
				log "in splitter group 1" --> "in splitter group 1"
				class of UI elements --> { …, tab group, … }
				tell tab group 1
					log "in tab group 1" --> "in tab group 1"
					class of UI elements --> { …, group, … }
					tell group 1
						log "in group 1" --> "in group 1"
						class of UI elements --> { …, group, … }
						tell group 1
							log "in group 1 of group 1" --> "in group 1 of group 1"
							class of UI elements --> { …, scroll area, … }
							tell scroll area 1
								log "in scroll area 1" --> "in scroll area 1"
								class of UI elements --> { …, UI element, … }
								tell UI element 1
									log "in UI element 1" --> "in UI element 1"
									class of UI elements --> { …, group, group, group, group, group, group, group, group, … }
									tell group 1
										log "in group 1" --> "in group 1"
										class of UI elements --> { …, ???, … }
									end tell
									tell group 2
										log "in group 2" --> "in group 2"
										class of UI elements --> { …, ???, … }
									end tell
									tell group 3
										log "in group 3" --> "in group 3"
										class of UI elements --> { …, ???, … }
									end tell
									tell group 4
										log "in group 4" --> "in group 4"
										class of UI elements --> { …, ???, … }
									end tell
									tell group 5
										log "in group 5" --> "in group 5"
										class of UI elements --> { …, ???, … }
									end tell
									tell group 6
										log "in group 6" --> "in group 6"
										class of UI elements --> { …, ???, … }
									end tell
									tell group 7
										log "in group 7" --> "in group 7"
										class of UI elements --> { …, ???, … }
									end tell
									tell group 8
										log "in group 8" --> "in group 8"
										class of UI elements --> { …, pop up button, … }
										tell pop up button 1
											-- get the name of the pop up
											set itsName to its name -->
											-- get the name of the selected menu item
											set itsValue to its value
											-- reveal the menu items
											click it
											tell menu 1
												-- grab the name of menu items
												set menuItems to name of menu items
												--> { name1, name2, name3, name4, name5, name6, … }
												-- supposed to click a menu item
												-- click menu item (one of the strings in menuItems)
											end tell
										end tell
									end tell
								end tell
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

Urge the editor to display the Events and to display the window “Log History”
This way you will see the lists of UI elements belonging to every level of the hierarchy.
Complete the fake lists which I typed.
We will see what is really failing.
I’m wondering if the pop up is really in group 8.

It would be fair to post here the content of the window “Log History”

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 4 janvier 2020 22:46:01

Thank you again.
1st the pop up I think has to be correct because I step though it to what I have presently set as the last item and it works. Of course I do not know if that will always be in the same position. I have run your script and it stalls in the same place.

This is the reply from running your script and you can see the error at the end.

tell application “System Events”
set frontmost of process “Safari” to true
get name of window 1 of process “Safari”
→ “MacScripter / Post a reply”
(in window)
get class of every UI element of window “Portfolio” of process “Safari”
→ {splitter group, button, button, button, group, button, toolbar}
(in splitter group 1)
get class of every UI element of splitter group 1 of window “Portfolio” of process “Safari”
→ {splitter, tab}
(in tab group 1)
get class of every UI element of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {group}
(in group 1)
get class of every UI element of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {group}
(in group 1 of group 1)
get class of every UI element of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {scroll area}
(in scroll area 1)
get class of every UI element of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {UI element, scroll bar}
(in UI element 1)
get class of every UI element of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {group, group, group, group, group, group, group, group, group, table, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, scroll area, scroll bar, group, group, group}
(in group 1)
get class of every UI element of group 1 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {group, group, group, group, group}
(in group 2)
get class of every UI element of group 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {}
(in group 3)
get class of every UI element of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {}
(in group 4)
get class of every UI element of group 4 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {}
(in group 5)
get class of every UI element of group 5 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {}
(in group 6)
get class of every UI element of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {}
(in group 7)
get class of every UI element of group 7 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {}
(in group 8)
get class of every UI element of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ {static text, pop up button, button, button}
get name of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ missing value
get value of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ “All portfolios”
click pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of application process “Safari”
get name of every menu item of menu 1 of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
→ error number -1719 from menu 1 of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”
Result:
error “System Events got an error: Can’t get menu 1 of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio" of process "Safari". Invalid index.” number -1719 from menu 1 of pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window “Portfolio” of process “Safari”

Tried to add a screen shot of the pop up when its clicked but could not beyond me but pop up shows

All Portfolios
eTrade Unallocated
eTrade 2006
etc

Again thank you for taking the trouble to help me

Model: MacBook Pro
AppleScript: 2.7
Browser: Safari 605.1.15
Operating System: macOS 10.14

Thanks.
It seems that the pop up button doesn’t respond to ‘click it’.
I already encountered UI elements unable to accept the standard way to trigger them.
The script below allow you to test two alternate ways to reveal the menu items.

set useClicClick to true -- EDITED TO USE CLICLICK try with both settings
-- false --> to use perform action "AXPress"
-- true --> to use the free CLI cliclick

set delayWithShell to false -- try with both settings
-- false --> to standard delay
-- true --> to use shell delay

tell application "System Events"
	tell process "Safari"
		set frontmost to true
		name of windows --> { "MacScripter / Post a reply", "Portfolio", …}
		tell window "Portfolio"
			-- class of UI elements --> {splitter group, button, button, button, group, button, toolbar}
			tell splitter group 1
				-- class of UI elements --> {splitter, tab}
				tell tab group 1
					-- class of UI elements --> {group}
					tell group 1
						-- class of UI elements --> {group}
						tell group 1
							-- class of UI elements --> {scroll area}
							tell scroll area 1
								-- class of UI elements --> {UI element, scroll bar}
								tell UI element 1
									-- class of UI elements --> {group, group, group, group, group, group, group, group, group, table, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, scroll area, scroll bar, group, group, group}
									tell group 1
										-- class of UI elements --> {group, group, group, group, group}
									end tell
									tell group 2
										-- class of UI elements --> {}
									end tell
									tell group 3
										-- class of UI elements --> {}
									end tell
									tell group 4
										-- class of UI elements --> {}
									end tell
									tell group 5
										-- class of UI elements --> {}
									end tell
									tell group 6
										-- class of UI elements --> {}
									end tell
									tell group 7
										-- class of UI elements --> {}
									end tell
									tell group 8
										-- class of UI elements --> {static text, pop up button, button, button}
										tell pop up button 1
											-- set itsName to its name --> missing value
											-- set itsValue to its value --> "All portfolios"
											-- reveal the menu items
											(*
											-- it seems that this instruction is not understood
											click it
											*)
											-- try an alternate way to reveal the menu items
											if useClicClick then
												-- grab cliclick from https://www.bluem.net/en/projects/cliclick/
												-- Install it at the path : "/usr/local/bin/cliclick"
												-- Use it to click upon the pop up button
												do shell script "/usr/local/bin/cliclick c:" & xLeft & "," & yTop
											else
												perform action "AXPress"
											end if
											if delayWithShell then
												repeat 20 times
													do shell script ("sleep 0.1")
													if exists menu 1 then exit repeat
												end repeat
											else
												-- alternate loop
												repeat 20 times
													delay 0.1
													if exists menu 1 then exit repeat # The menu is expanded
												end repeat
											end if
											if (not (exists menu 1)) then error "The menu 1 really refuse to appear!"
											tell menu 1
												-- grab the name of menu items
												set menuItems to name of menu items
												--> { name1, name2, name3, name4, name5, name6, … }
												-- supposed to click a menu item
												-- click menu item (one of the strings in menuItems)
											end tell
										end tell
									end tell
								end tell
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 5 janvier 2020 12:21:16

Cleaned a bit to stop logging several values
Added a property to rule the loop used to delay.
At least one old version of macOS behaved wrongly with standard delay
EDITED TO USE CLICLICK

Thanks again, unfortunately it stops at “The menu1 really does not exist”, but it does.

This is the bit of the code I use to select a portfolio I have just created which works.


	                --Select "All Portfolios" Open Portfolio just created
			repeat 20 times
				try
					click pop up button 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "Portfolio"
					exit repeat
				end try
				delay 0.25
			end repeat
			--It will be the last one step through each it should only need 6 repeats but it can stall
			repeat 10 times
				key code 125
				delay 1
			end repeat
			--Accept Last Selection the Portfolio just created
			key code 36

As you can see its very clumsy, I run the repeat 10 time just to make sure I get the last entry, then key code 36 accepts the last one and opens that portfolio. I do not know how to add a screen shot on this site but if I could I would be able to show the result of clicking the pop up button which is all of the existing portfolios. What I need is the number of items in the pop up button to set the number of times the repeat block has to cycle. It would also be useful to know the name of each item in case I wanted to do something with that portfolio at a later date.

I have discovered with this web site that you cannot always just click a button, although that is not the question with this particular button. When necessary to solve that issue I use a slightly different repeat block in the 1st instance shown below. The function is to select the field to enter the stock symbol then enter it then click “OK” to confirm the entry.


                      on SetStockSymbol(Sym)
	--display dialog "Stock " & Sym
	tell application "System Events"
		tell process "Safari"
			repeat 20 times
				try
					tell text field 1 of group 20 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "ADVFN - Portfolio - Add Buy"
						set {xPosition, yPosition} to position
						set {xSize, ySize} to size
					end tell
					-- modify offsets if hot spot is not centered:
					click at {xPosition + (xSize div 2), yPosition + (ySize div 2)}
					exit repeat
				end try
				delay 0.25
			end repeat
			
			repeat 20 times
				try
					--display dialog "Symbol " & Sym
					set value of text field 1 of group 20 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "ADVFN - Portfolio - Add Buy" to Sym
					exit repeat
				end try
				delay 0.25
			end repeat
			
			repeat 20 times
				try
					click button "OK" of group 20 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "ADVFN - Portfolio - Add Buy"
					exit repeat
				end try
				delay 0.25
			end repeat
		end tell
	end tell
	--display dialog "Stock Set"
end SetStockSymbol


Once again my thanks for all your help. As I said I can make do with what I have done but its far from satisfactory.

Peter

Must I understand that triggering ClicClick doesn’t reveal the menu items. ?

This is ruled by an instruction at the very beginning:

set useClicClick to false -- try with both settings
-- false --> to use perform action "AXPress"
-- true --> to use the free CLI cliclick

I don’t remember encountering a UI element which doesn’t react to cliClick.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 5 janvier 2020 20:55:20

Yes it does reveal the menu items in the pop up button. The 1st one “All Portfolios” is visible before the click, after your AxPress command the list appears. In my code using Key code 125 and a short delay I can see it stepping through each one, at the end of my repeat ket code 36 selects the last one. All portfolios is not an actual option as that is what is showing on the web page, so the 1st option is the next line , to sure it that is relevant. If I could work out how to post a screen shot I could show you the result of AXPress

I tried adding a 2 sec delay after your AXPress then a dialogue to check Name, Title, ID and Index all failed. Also tried the last 2 as integer and the first two as string’s the latter result “invalid index”.

In my script I can get the value of the pop up button and it is always “All Portfolios”

Thanks again

Peter

It’s not clear if you have tested the option using the shell script instruction:

do shell script "/usr/local/bin/cliclick c:" & xLeft & "," & yTop

I edited the message #8 so that it defaults with cliclick which, as is written in the script, must be installed by yourself.

– grab cliclick from https://www.bluem.net/en/projects/cliclick/
– Install it at the path : “/usr/local/bin/cliclick”

If the menu items appear, it’s that menu 1 exists.
So you were supposed to see the names of these menu items in the Log History

											tell menu 1
												-- grab the name of menu items
												set menuItems to name of menu items
												--> { name1, name2, name3, name4, name5, name6, … }
												-- supposed to click a menu item
												-- click menu item (one of the strings in menuItems)
											end tell

If it appear, it’s what you are supposed to see where I wrote: → { name1, name2, name3, name4, name5, name6, … }
You will have to edit the instruction:
– click menu item (one of the strings in menuItems)
by removing the “–” and replacing (one of the strings in menuItems) by the real name of a menu item or by it’s index in the list.

You may send a screenshot at <koenigyvan (at) mac.com>
My mail address is ‘modified’ so that it can’t be triggered by robots.
Just replace " (at) " by “@”

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 6 janvier 2020 04:40:03

Download cliclick from https://www.bluem.net/en/projects/cliclick/
Install it at the path : “/usr/local/bin/cliclick” before running this script.

Below is a version designed to use cliclick two times.

(1st) to reveal the menu items
(2nd) to click the 3rd menu item

tell application "System Events"
	tell process "Safari"
		set frontmost to true
		name of windows --> { "MacScripter / Post a reply", "Portfolio", …}
		tell window "Portfolio"
			-- class of UI elements --> {splitter group, button, button, button, group, button, toolbar}
			tell splitter group 1
				-- class of UI elements --> {splitter, tab}
				tell tab group 1
					-- class of UI elements --> {group}
					tell group 1
						-- class of UI elements --> {group}
						tell group 1
							-- class of UI elements --> {scroll area}
							tell scroll area 1
								-- class of UI elements --> {UI element, scroll bar}
								tell UI element 1
									-- class of UI elements
									--> {group, group, group, group, group, group, group, group, group, table, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, scroll area, scroll bar, group, group, group}
									tell group 8
										-- class of UI elements --> {static text, pop up button, button, button}
										set {{xleft, yTop}, {w, h}} to {position, size} of pop up button 1 -- ADDED
										tell pop up button 1
											-- set itsName to its name --> missing value
											set itsValue to its value --> "All portfolios"
											-- try to reveal the menu item
											-- Use cliclic to click upon the pop up button
											tell me to do shell script "/usr/local/bin/cliclick c:" & (xleft + w div 2) & "," & (yTop + h div 2)
											
											repeat 20 times
												delay 0.1
												if exists menu 1 then exit repeat # The menu is expanded
											end repeat
											
											if (not (exists menu 1)) then error "The menu 1 really refuse to appear!"
											tell menu 1
												-- grab the name of menu items
												set menuItems to name of menu items
												--> { name1, name2, name3, name4, name5, name6, … }
												-- supposed to click a menu item 3
												set {{xleft, yTop}, {w, h}} to {position, size} of menu item 3 -- ADDED, get the coordinates of the 3rd menu item
												tell me to do shell script "/usr/local/bin/cliclick c:" & (xleft + w div 2) & "," & (yTop + h div 2) -- ADDED,  click it
											end tell
										end tell
									end tell
								end tell
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

If it works, it will be easy to edit it so that it click the menu item with a given name.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 6 janvier 2020 05:37:24

Without third-party software:


tell application "Safari" to activate
tell application "System Events" to tell application process "Safari"
	tell table 1 of UI element 1 of scroll area 1 of UI element 1 of group 1 of tab group 1 of splitter group 1 of window 1
		
		-- Click portofolio whose name is "eTrade Unallocated"
		repeat with i from 3 to (count rows) - 1 -- counting all your portofolios + 3 here
			tell UI element 3 of row i to tell first UI element
				if its name is "eTrade Unallocated" then
					click it
					exit repeat
				end if
			end tell
		end repeat
		
	end tell
end tell
tell application "Safari" to activate

As the source is obviously a website I would prefer a do JavaScript solution over GUI scripting but this depends strongly on the source code of the site.

Interesting idea. I’ll see what i can do.

Here is a modified proposal.
It rely of this scheme:

set itsValue to "All portfolios"

set menuItems to {"name1", "name2", "name3", "All portfolios", "name5", "name6"}
set delim to character id 128127 & character id 128520
set asText to my recolle(menuItems, delim)
log asText -->(*name1????????name2????????name3????????All portfolios????????name5????????name6*)
set theEnd to item 2 of my decoupe(asText, itsValue & delim)
log theEnd --> (*name5????????name6*)
set wanted to item 1 of my decoupe(theEnd, delim)
log wanted --> (*name5*)

#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====

Embedded in the script it give:

tell application "System Events"
	tell process "Safari"
		set frontmost to true
		name of windows --> { "MacScripter / Post a reply", "Portfolio", …}
		tell window "Portfolio"
			-- class of UI elements --> {splitter group, button, button, button, group, button, toolbar}
			tell splitter group 1
				-- class of UI elements --> {splitter, tab}
				tell tab group 1
					-- class of UI elements --> {group}
					tell group 1
						-- class of UI elements --> {group}
						tell group 1
							-- class of UI elements --> {scroll area}
							tell scroll area 1
								-- class of UI elements --> {UI element, scroll bar}
								tell UI element 1
									-- class of UI elements
									--> {group, group, group, group, group, group, group, group, group, table, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, scroll area, scroll bar, group, group, group}
									tell group 8
										-- class of UI elements --> {static text, pop up button, button, button}
										set {{xleft, yTop}, {w, h}} to {position, size} of pop up button 1 -- ADDED
										tell pop up button 1
											-- set itsName to its name --> missing value
											set itsValue to its value --> "All portfolios"
											-- try to reveal the menu item
											-- Use cliclic to click upon the pop up button
											tell me to do shell script "/usr/local/bin/cliclick c:" & (xleft + w div 2) & "," & (yTop + h div 2)
											
											repeat 20 times
												delay 0.1
												if exists menu 1 then exit repeat # The menu is expanded
											end repeat
											
											if (not (exists menu 1)) then error "The menu 1 really refuse to appear!"
											tell menu 1
												-- grab the name of menu items
												set menuItems to name of menu items
												--> {"name1", "name2", "name3", "All portfolios", "name5", "name6"}
												set delim to character id 128127 & character id 128520
												set asText to my recolle(menuItems, delim)
												log asText -->(*name1????????name2????????name3????????All portfolios????????name5????????name6*)
												set theEnd to item 2 of my decoupe(asText, itsValue & delim)
												log theEnd --> (*name5????????name6*)
												set wanted to item 1 of my decoupe(theEnd, delim)
												log wanted --> (*name5*)
												-- supposed to click a menu item below the original one
												set {{xleft, yTop}, {w, h}} to {position, size} of menu item wanted -- ADDED, get the coordinates of the original menu item
												tell me to do shell script "/usr/local/bin/cliclick c:" & (xleft + w div 2) & "," & (yTop + h div 2) -- ADDED,  click it
											end tell
										end tell
									end tell
								end tell
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====

Hi

A quick Note to acknowledge your help once again. Unfortunately my MacBook Pro decided to go down on me this morning and no amount of trying has got it back so far. I have it at a local outfit that claims to fix Mac’s they appeared to be licensed by Apple so hears hoping. Also found my back up has gone south. Anyway cannot access my scripts although I have printouts of most so could rebuild in time.

Anyway did not want you to think I had ignored your help. Will be in touch when I get sorted out.

Thanks

Peter