Choose item from dropdown


How can i select the value from the dropdown.
This is my UI.

I will click on the arrow and the dropdown will open.
This is one of the dropdown choice:
My xpath for the arrow is:
(//div[contains(@class,‘select2-container’) and contains(@class,‘form-control’) and contains(@class,‘input-large’) and contains(@class,‘categoryList_labelDetail’)])[1]

My xpath for the item to be selected is : //*[@id=‘select2-result-label-203’]

I have tried to click on the id but it is not selecting my choice.
This is part of the script which is not working.‘To/DropdownCarburant’)) //opening the dropdown with the arrow‘To/selectCarburant’)) //clicking on the item

It is opening the dropdown but not able to go to the item chosen.

I do not want to set text in the search bar and click on it, I want to really choose the item from the dropdown.
I need two advises.

  1. How can i choose from the dropdown.
  2. The dropdown has a long list of items, how to make sure it can scroll on the dropdown to get the item selected.

Please do let me know if any other info is required.

Thank you.

Thanks for making your question so clear. :clap:

I’m wondering if the dropdown is filled asynchronously. If it is, it might take a little while to populate the list. Did you try inserting a delay BEFORE you click on the item you want to select?

Also, did you get any error printed in the console?

@anuradha I don’t think that is the correct manner for the search box. I believe you are supposed to start typing some characters into the box and then the drop-down list reduces from millions to only having a few. What I have been doing is:

WebUI.setText(findTestObject('to'), 'Nouve')
WebUI.clickOffset(findTestObject('to'), 45, 45)

What this does is starts the drop-down to display those references that begin with “Nouve”, such as the first one in the list above, Nouvel emprunt, and then I click on where the reference should be, just below the search box (I made an assumption that every box is 35 pixels in height on my system). So the 45, 45 are X and Y offsets from the top left corner of the search box to move 45 pixels to the right and 45 pixels down from the top left corner of the search box.

If you really don’t care what you select from the drop-down list, then just try to use the WebUI.clickOffset(findTestObject('to'), 45, 45) statement by itself.

Hope that helps.