How to select data in select2-selection using Katalon

Issue:

I’m trying to enter data in a select2-selection but I can’t get it to work.

Any help would be highly appreciated.

There are multiple ways to handle select2 elements. Can you please share the HTML for one of those dropdowns, as well as the test code you are currently using to try and set the value? Thanks.

Try this : WebUI.selectOptionByLabel(findTestObject(‘YourPageName/YourPageObjectName’), ‘Katalon_Template_1’, false)

As of now I am using send keys method, but since the script is unable to click on dropdown arrow button it is not going through.

WebUI.click(findTestObject(‘Object Repository/Test Objects/Pages/Page_Dashboard - Jobsparks/Job/span_Please Select_select2-selection__arrow’))

WebUI.setText(findTestObject(‘Object Repository/Test Objects/Pages/Page_Dashboard - Jobsparks/Job/input_Please Select_select2-search__field (1)’),‘Stofer Smith’)

WebUI.sendKeys(findTestObject(‘Object Repository/Test Objects/Pages/Page_Dashboard - Jobsparks/Create_Client_Objects/input_Please Select_select2-search__field (1)’),Keys.chord(Keys.ENTER))

I have tried it but since it is select2 control it is not working for it.

The HTML snippet in your screenshot does not show the true element for the dropdown, rather, it’s showing a parent <span> element. Can you expand the span all the way down until you find either a <select> element or an <input> element?

Either of these will usually be the type of element you actually want to manipulate to set the field.

Let me know if you need any other details

I would try a simple solution first:

1.) Create a test object with the following XPath:

//label[normalize-space()='Tech']/following-sibling::div/select

2.) Try setting this as if it were a normal select. If you successfully identify the <select> element using the above xpath, then @francoarebuffi’s answer might work:

WebUI.selectOptionByLabel(findTestObject('path/to/test/object'), 'Stofer Smith', false);

Let me know if this works. If it doesn’t we’ll try something else.

1 Like

It should, indeed. aria-hidden should not affect operability:

https://www.w3.org/WAI/PF/aria/states_and_properties#aria-hidden

And, for completeness:

https://www.w3.org/WAI/PF/aria/states_and_properties#aria-disabled

Sure I will give it try and let you know. Thanks