I need to be able to pull the list of items available in a Select dropdown, so searched these forums and found the following item: How to get text list from dropdown
Going off that item, I created the following code logic in order to pull the options list into a WebElement:
//Build Test Object and retrieve dropdown array values
TestObject desiredDropdown = new TestObject ("Retrieving values for filter dropdown " + current_page + " -> " + filter_name)
desiredDropdown.addProperty('xpath', ConditionType.EQUALS, filter_object_xpath)
WebElement selectElement = WebUiCommonHelper.findWebElement(desiredDropdown, 10)
Select thisSelect = new Select(selectElement);
List<WebElement> options = thisSelect.getOptions();
However, on the āSelect this Selectā¦ā line Iām getting the following error: āGroovy:You cannot create an instance from the abstract class ācom.sun.org.apache.bcel.internal.generic.Selectā.ā
Anyone able to determine how to get around this issue?
If thereās a better way to retrieve the values from the Select into a List object Iām game for changing my approach to whatever is suggested as well.
Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.
In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!
Hello @kevin.jackey, I found the following using Copilot, give it a try or try your own search:
The error youāre encountering, āYou cannot create an instance from the abstract class ācom.sun.org.apache.bcel.internal.generic.Selectā,ā suggests that there is a conflict or misinterpretation between the Select class youāre trying to use and another Select class from the com.sun.org.apache.bcel.internal.generic package.
In your code, you are likely intending to use the Select class from the Selenium library, which is used to interact with dropdown elements in web pages. However, due to a naming conflict, Groovy is mistakenly trying to use the Select class from the com.sun.org.apache.bcel.internal.generic package, which is abstract and cannot be instantiated.
To resolve this, you need to ensure that you are importing the correct Select class from the Selenium library. Hereās how you can modify your code:
By explicitly importing the Select class from the Selenium library, you ensure that Groovy uses the correct class, avoiding the conflict with the abstract class from the com.sun.org.apache.bcel.internal.generic package.
String selectedDropdownValue = ''
KeywordUtil.logInfo("Selecting dropdown filter option " + selection_type + " for filter " + filter_name + " on page " + current_page + " ,xpath " + filter_object_xpath)
//Allow time for filter options to populate
WebUI.delay(5)
//Build Test Object and retrieve dropdown array values
TestObject desiredDropdown = new TestObject ("Retrieving values for filter dropdown " + current_page + " -> " + filter_name)
desiredDropdown.addProperty('xpath', ConditionType.EQUALS, filter_object_xpath)
WebElement selectElement = WebUiCommonHelper.findWebElement(desiredDropdown, 10)
Select thisSelect = new Select(selectElement);
List<WebElement> options = thisSelect.getOptions();
//Retrieve dropdown element value based on if a dropdown value is explicitly specified and (if not) if the calling function specifies using the first dropdown value or a random dropdown value
if (desired_filter_value > '') {
selectedDropdownValue = desired_filter_value
KeywordUtil.logInfo("Desired Dropdown Value = " + selectedDropdownValue)
} else if (selection_type == 'first') {
selectedDropdownValue = options.get(1).getText();
KeywordUtil.logInfo("First Dropdown Value = " + selectedDropdownValue)
}
KeywordUtil.logInfo("Indicated Dropdown Value = " + selectedDropdownValue)
This line returned a valid reference to an <select aria-hidden="true"> element. It implies that aria-hidden attribute seems to have nothing significant.
I guess, @kevin.jackey has some other reason of his issue.
Actually I believe you were correct based on what Iām finding in other articles and questions around the aria-hidden=ātrueā setting.
Based on the above, I set about following a different path and capturing all the li elements that appear when the input box for the select is clicked. This is definitely working, except for some reason the click Iām trying to do in the below section isnāt actually selecting the item in the list. It does show the correct text name for that element, however, so Iām a bit stumped, any ideas?
//Allow time for filter options to populate
WebUI.delay(5)
KeywordUtil.logInfo("Selecting dropdown filter option: " + selection_type + " for filter: " + filter_name + " on page: " + current_page + " - xpath: " + filter_object_xpath)
//Build Test Object and retrieve dropdown array values
TestObject desiredDropdown_values = new TestObject ("Retrieving values for filter dropdown " + current_page + " -> " + filter_name)
desiredDropdown_values.addProperty('xpath', ConditionType.EQUALS, filter_object_xpath)
List <WebElement> page_name_options = WebUiCommonHelper.findWebElements(desiredDropdown_values, 10)
KeywordUtil.logInfo('The size of page_name_options is : ' + page_name_options.size())
//Retrieve dropdown element value based on if a dropdown value is explicitly specified and (if not) if the calling function specifies using the first dropdown value or a random dropdown value
if (desired_filter_value > '') {
selectedDropdownValue = desired_filter_value
KeywordUtil.logInfo("Desired Dropdown Value = " + selectedDropdownValue)
} else if (selection_type == 'first') {
selectedDropdownValue = page_name_options.get(0).getText()
KeywordUtil.logInfo("First Dropdown Value = " + selectedDropdownValue)
selectedDropdownValue = page_name_options.get(0).click()
WebUI.delay(2)
}
I can not reproduce your problem on my machine. So I donāt really understand your problem.
I have no idea.
Just a chat:
ARIA ā Accessible Rich Internet Application ā is a fairly new problem domain. According to WAI-ARIA Overview | Web Accessibility Initiative (WAI) | W3C, the W3C RFC was published June 2023 = 16months ago, which is recent enough for the browser development job. I think that browsers may have something āto be developed yetā (so called, bugs) for the small things.