int w=wait(3 WV win("Introducing the HTML5 “Menu” and “Menuitem” Elements - Google Chrome""Chrome_WidgetWin_1")) Acc a.Find(w "MENUITEM""Español"""0x30013)
a.DoDefaultAction
now in version 81 when you run the code the menu opens, but it is not automatically selected.
Could you tell me if there is any flag in Chrome 81 that can be activated to make the code work, or if not, how to modify the code so that the item is selected automatically.
int w=wait(3 WV win("Introducing the HTML5 “Menu” and “Menuitem” Elements - Google Chrome""Chrome_WidgetWin_1")) Acc a.Find(w "STATICTEXT""Languages:"""0x300100"next")
a.CbSelect("Español")
Somehow object roles sometimes change. Sometimes the combo box is COMBOBOX and item is LISTITEM, and the macro works. Sometimes BUTTONMENU and MENUITEM, and the macro fails. It seems it changes to COMBOBOX when I use the "Find acc object" dialog. The works until restarting Chrome.
This modified CbSelect supports MENUITEM.
Member function Acc.CbSelect2
;item - item text. Exact or with *?. Case insensitive. Or 0-based index. ;flags: ;;;1 - always show popup list (temporarily). ;;;2 - use different method. Need this for MS Office toolbar comboboxes and some other non-standard comboboxes, especially if editable. Also try flags 2|1. ;;;4 - use different method. Faster. Can be used with Firefox, Chrome and some other windows. Works not with all objects. ;;;8 - use different method with standard combo box. Also you can try flags 8|1.
;REMARKS ;This object must have role COMBOBOX. In Chrome also can be BUTTONMENU. ;Works not in all windows. ;If does not work, try various flags and flag combinations, for example 1|2. ;Fast and reliable with: ;;;Standard combo box controls. ;;;Internet Explorer and IE-based web browsers/controls. ;Slower and less reliable with: ;;;Firefox, Chrome. ;;;MS Office dialogs. ;;;MS Office toolbars. Use flag 2. Window must be active. ;;;Java windows. Use flags 2 or 2|1 for editable comboboxes. ;Does not work with: ;;;Windows 7 Wordpad and similar windows. ;In most windows sets focus to the combo box. ;In some windows works only if the window is active. For example Chrome. ;The autodelay (spe) may be applied, depending on browser and flags.
;Errors: ERR_INIT, ERR_ITEM, ERR_FAILED (failed to select).
if(!a)endERR_INIT
Htm e int b=__HtmlObj(e)
if b=1;;IE ,if flags&1 ,,Acc ab.Find(a "PUSHBUTTON");;DoDefaultAction and e.Click don't work ,,if(ab.a) ab.DoDefaultAction; ab.DoDefaultAction ,e.CbSelect(item 2) ,errendiif(_error.code=ERRC_ITEMERR_ITEMERR_FAILED) ,ret
int hc isSimpleCB
hc=child(a)
isSimpleCB=!b andSendMessage(hc CB_GETITEMHEIGHT-10) if(b=2andWinTest(hc "Chrome_*")) b=3
if flags&1and b!3;;in Chrome do later, now clears items ,Select(1);err;;info: it activates window of standard CB. Works without this, but then activates later. ,if(isSimpleCB)SendMessage(hc CB_SHOWDROPDOWN10);if(flags&8=0)SendMessage(hc CB_SHOWDROPDOWN00);;info: DoDefaultAction fails ,elseDoDefaultAction elseif isSimpleCB and flags&2=0 ,SendMessage(GetParent(hc)WM_COMMANDCBN_DROPDOWN<<16|GetWinId(hc) hc);;for auto-fill controls
;get list object Acc ai aList;str role="LISTITEM"
ai.Find(a role """"0x10) if!ai.a ,role="MENUITEM" ,ai.Find(a role """"0x10) if ai.a ,ai.Navigate("pa" aList) else;;maybe "list/label" in Java. Or 0 items, or not combobox. ,aList.Find(a "list"""""0x10) ,if(!aList.a) aList=this
STRINT si sel item.vt ,caseVT_I4 ,si.i=item.lVal+1 ,ai.Find(aList.a role """"0x500 si.i) , ,caseVT_BSTR ,si.s=item ,ai.Find(aList.a role """"0x5000""&sub.Callback&si);;info: callback gets item index , ,caseelseendERR_BADARG if(!ai.a)endERR_ITEM
if isSimpleCB and flags&8=0 ,CB_SelectItem hc si.i-1 ,ret
if(flags&4) ai.DoDefaultAction;ret
if flags&1 ,if b=3 ,,Select(1);err ,,DoDefaultAction;;tested: Chrome sometimes changes STATE_SYSTEM_COLLAPSED, sometimes not else ,Select(1);err ,if(flags&2=0and!b)DoDefaultAction;err flags|2;;show popup list. In Office would defocus instead.
;keys if(flags&2=0)sub.PostKey hc VK_HOME;elserep(aList.ChildCount)sub.PostKey hc VK_UP;;Home does not work in Office toolbars rep(si.i-1)sub.PostKey hc VK_DOWN
;need Enter to close popup (flag 1) or submit if flags&1=0and!isSimpleCB ,if(b!3) flags|1;;in Chrome Enter shows CB list if flags&1 ,if(b=3)0.1;;in Chrome async, may not close if too early ,sub.PostKey hc VK_RETURN
#sub PostKey function h vk PostMessage h WM_KEYDOWN vk 0 PostMessage h WM_KEYUP vk 0 ;tested: SendMessage does not work. PostMessage works better than key.
;notes: ;ai.DoDefaultAction etc don't work. In FF selects, but does notify FF; then keyboard navigation does not work. ;In windows other than IE/FF/Chrome/simpleCB: ;;;In most windows works well only with popup list (this.DoDefaultAction). ;In FF could post first char several times. Faster but not reliable. Or could post PageDown, but difficult.
;For listboxes: ;With simple listbox and IE, can use Select(). ;In Firefox Select() does not work. To select single item, can use DoDefaultAction or this func.