enter data in select2-selection



I’m trying to enter data in a select2-selection but I can’t get it to work. I have been searching for others with the same problem en from that I got this code:
import org.openqa.selenium.WebDriver
import org.openqa.selenium.support.ui.Select

import org.openqa.selenium.StaleElementReferenceException
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.ui.Select

import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.common.WebUiCommonHelper
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

try {
WebUI.selectOptionByValue(findTestObject(‘registration/Page_Staging/span_select2-selection select2’), ‘registration/Page_Staging/li_Belgian’, true)
catch (StaleElementReferenceException e) {
TestObject to = findTestObject(‘registration/Page_Staging/span_select2-selection select2’)
WebElement webElement = WebUiCommonHelper.findWebElement(to)
new Select(WebUiCommonHelper.findWebElement(findTestObject(‘registration/Page_Staging/span_select2-selection select2’), 2)).selectByValue(“Belgian”)


But the dropbox doesn’t get filled. I have this errormessage:

Test Cases/registration collaborator FAILED because (of) Unable to select option by value ‘registration/Page_Staging/li_Belgian’ of object ‘Object Repository/registration/Page_Staging/span_select2-selection select2’ using regular expression (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/registration/Page_Staging/span_select2-selection select2’ located by ‘By.xpath: //span[count(. | //[@class = ‘select2-selection select2-selection–single’]) = count(//[@class = ‘select2-selection select2-selection–single’])][count(. | //[@role = ‘combobox’]) = count(//[@role = ‘combobox’])][count(. | //[@aria-haspopup = ‘true’]) = count(//[@aria-haspopup = ‘true’])][count(. | //[@aria-expanded = ‘true’]) = count(//[@aria-expanded = ‘true’])][count(. | //[@tabindex = ‘0’]) = count(//[@tabindex = ‘0’])][count(. | //[@aria-labelledby = ‘select2-volunteers_volunteer_nationality-container’]) = count(//[@aria-labelledby = ‘select2-volunteers_volunteer_nationality-container’])][count(. | //[@aria-owns = ‘select2-volunteers_volunteer_nationality-results’]) = count(//[@aria-owns = ‘select2-volunteers_volunteer_nationality-results’])][count(. | //[@id=“edit_volunteers_volunteer_1458”]/div[1]/div[1]/div[2]/div[2]/span/span[1]/span) = count(//[@id=“edit_volunteers_volunteer_1458”]/div[1]/div[1]/div[2]/div[2]/span/span[1]/span)]’ not found)

I inspected the page and copied the path into the xpath.

Can you advise on how to solve this. I have more dropdowns of the same type.



I solved it by adjusting the settings of the select2 field in the repository, thanks to Oliver of the Katalon support team


Please can you be kinldy enough to share your findings? or anyone @ Katalon can provide the info?


Els Van Och said:

I solved it by adjusting the settings of the select2 field in the repository, thanks to Oliver of the Katalon support team

please can you give me more details ? Thank you