Forum Discussion

MadGrb's avatar
MadGrb
Contributor
5 years ago

WPFObject() for ListBox without index not working

WPFObject for ListBox without index not working
Hi,

I have a special listbox. So, I have to work with WPFObject(), but this method doesn't work without an index.

Look to my Codes

 

 SelectListBoxItem(ListBox,Contain = ''):
    
        try:
        
                Delay(Time.OptTimes('Nix'))
                
                ListBox.Click()
                
                Item = Aliases.JTL_Wawi.Popup.Root.ListBoxEdit
                
                WaitForAvailablity(Item)
                
                if isinstance(Contain, int):
                        if Contain == 0 :
                                Contain = 1
                                
                        Item.WPFObject("ListBoxEditItem", '', Contain).Click()
                elif Contain == '':
                        Item.WPFObject("ListBoxEditItem", Contain,1).Click()
                else:
                        if Item.WPFObject("ListBoxEditItem", Contain).Exists:
                                Item.WPFObject("ListBoxEditItem", Contain).Click()
                        else:
                                Item.WPFObject("ListBoxEditItem","", 1).Click() 
                
        except Exception as exp:
                Log.Message('ListBoxEditItem - type:' + str(exp)) 
				
				
Please look this part

                        if Item.WPFObject("ListBoxEditItem", Contain).Exists:
                                Item.WPFObject("ListBoxEditItem", Contain).Click()

 

 

Please look this part

if Item.WPFObject("ListBoxEditItem", Contain).Exists:
Item.WPFObject("ListBoxEditItem", Contain).Click()


I get Error(Object not find) but with index, she is working :-(, unfortunatly, I do not know somthimes index.

  • I find a good way, I use find.

    look

    def SelectListBoxItem(ListBox,Contain = ''):
        
            try:
            
                    Delay(Time.OptTimes('Nix'))
                    
                    ListBox.Click()
                    
                    Item = Aliases.JTL_Wawi.Popup.Root.ListBoxEdit
                    
                    SubItem = Item.FindChild('WPFControlText',Contain,1)
                    
                    WaitForAvailablity(Item)
                    
                    if isinstance(Contain, int):
                            if Contain == 0 :
                                    Contain = 1
                                    
                            Item.WPFObject("ListBoxEditItem", '', Contain).Click()
                    elif Contain == '':
                            Item.WPFObject("ListBoxEditItem", Contain,1).Click()
                    else:
                            if SubItem.Exists:
                                    SubItem.Click()
                            else:
                                    Item.WPFObject("ListBoxEditItem","", 1).Click() 
                    
            except Exception as exp:
                    Log.Message('ListBoxEditItem - type:' + str(exp))     

     

  • I find a good way, I use find.

    look

    def SelectListBoxItem(ListBox,Contain = ''):
        
            try:
            
                    Delay(Time.OptTimes('Nix'))
                    
                    ListBox.Click()
                    
                    Item = Aliases.JTL_Wawi.Popup.Root.ListBoxEdit
                    
                    SubItem = Item.FindChild('WPFControlText',Contain,1)
                    
                    WaitForAvailablity(Item)
                    
                    if isinstance(Contain, int):
                            if Contain == 0 :
                                    Contain = 1
                                    
                            Item.WPFObject("ListBoxEditItem", '', Contain).Click()
                    elif Contain == '':
                            Item.WPFObject("ListBoxEditItem", Contain,1).Click()
                    else:
                            if SubItem.Exists:
                                    SubItem.Click()
                            else:
                                    Item.WPFObject("ListBoxEditItem","", 1).Click() 
                    
            except Exception as exp:
                    Log.Message('ListBoxEditItem - type:' + str(exp))