Select option listing - Cannot create instance from abstract class

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.

Thanks in advance!!

1 Like

Hi there, :wave:

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!

Thanks! :sunglasses:
Katalon Community team

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:

  1. Import the correct Select class:
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.ui.Select
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.common.WebUiCommonHelper
import com.kms.katalon.core.testobject.ConditionType
  1. Your updated code:
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()

options.each { option ->
    println option.getText()
}

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.

Aha! Thank you so much, one instance where ctrl + shift + 0 failed me :frowning:

Still having issues though and canā€™t figure out why.

Hereā€™s the Select object Iā€™m attempting to pull from, as seen there are definitely values present:

and my code snippet appears to be correct:

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)

Yet Iā€™m not getting any values:

Thought on this?

Is there a less complicated way to retrieve the first item value from the dropdown?

@kevin.jackey

The <select> element has an attribute aria-hidden="true"
image

According to the MDN document of aria-hidden,

The presence of the aria-hidden attribute hides content from assistive technology but doesnā€™t visually hide anything.

I think that WebDriver is a sort of assistive technology. So the <select> element is visible for human but would be hidden from WebDriver.

Please make sure if the WebUiCommonHelper.findWebElement(desiredDropdown, 10) returns a meaningful value or not.


How to get the <select aria-hidden="true">? ā€” Possiblly, the callJavaScript() will be the last resort.

Interesting, wasnā€™t aware that the hidden=true affected automation, will definitely need to figure out how the get around that, thanks!

I did a small experiment. That proved that I was wrong.

WebElement selectElement = WebUiCommonHelper.findWebElement(desiredDropdown, 10)

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)

		}
1 Like

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.

1 Like