Ask a Question

ClickItem for a WPF comboBox won't select an item by its caption, only by index

Oferv
Super Contributor

ClickItem for a WPF comboBox won't select an item by its caption, only by index

Hi,

we are using a WPF comboBox object in our app (System.Windows.Controls.ComboBox), I am trying unsuccessfully to select one of the comboBox items using its caption, it does work using index but, in this case, I can't use the index as once an item is selected the sorting of the items is mixed up. this comboBox has languages items in it so for the first time the app is loading and by default, the selected language will be English, and the sorting of the languages will be x and will be done by alphabetical order but, if I will select French (using an index for example) the sorting of the languages will change as all the languages are now written in French and they will get re-sorted by alphabetical order so, using an index is out of the question in this case. the only option here is to use the language caption. any idea how can I do that?

 

Thanks,

 

Ofer

16 REPLIES 16
rraghvani
Trusted Contributor

What properties are exposed in Object Browser for your combo box?

tristaanogre
Esteemed Contributor

I have seen in some situations that, if the caption of the combobox item has something other than text as part of it (some sort of icon, etc), then caption selection doesn't work.  Can you verify if the items are text only or do they have some sort of graphic component?


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

Hi tristaanogre,

 

There are no icons but there's more than one caption. see attached

 

 

Oferv
Super Contributor

Hi rraghvani,

please find attached

rraghvani
Trusted Contributor

Have you read through Testing WPF Applications? You might be able to access the object using WPFObject

Oferv
Super Contributor

Yes I did but, in there it says that the items can be selected using clickitem using caption and this does not work for me https://support.smartbear.com/testcomplete/docs/app-testing/desktop/wpf/control-support.html

When trying to record the item clicking, TC is using index and not caption

 

def Test1():
App = Aliases.DesignerProcess
comboBox = App .DesignerMainWindow.BackstageViewMenu.BackStageWindowPanels.OptionsTabBackStageWindow.LanguageOptionComboBox
comboBox.ToggleButton.ClickButton(cbChecked)
App .HwndSource_PopupRoot.PopupRoot.DropDownScrollViewer.VScroll.Pos = 182.32000000000002
comboBox.ClickItem(8)
App .HwndSource_DominoMessageBox3.DominoMessageBox.ButtonOk.ClickButton()

 

While I want to use comboBox.ClickItem("English") or any other optional language

rraghvani
Trusted Contributor

I think it might be possible to select the item based on the name, but you will have to try and see how the name is constructed e.g. "Finnish\rsuomi". 

rraghvani_0-1679669719464.png

Does the Methods tab give some indication as to what method to use to select an item?

 

If you combo box is a custom control, then it may be tricky to select the item based on name. See WPF ComboBox Support

Oferv
Super Contributor

Sorry, there are so many methods, not sure how to copy-paste them all. taking screenshots of each will take ages. do you want to search for specific methods? i.e search for items/select/click etc.?

 

How would you use the properties you've marked in your screenshot to select an item? I've tried and couldn't find a way to do that. can you please give an example?

 

Thanks,

 

Ofer

rraghvani
Trusted Contributor

Click on the three little dots ... to drill down into the object, there may be some clues as to how to select the item.

cancel
Showing results for 
Search instead for 
Did you mean: