Dears ,
please support as I received below error while selecting an element from dropdownlist
=============== ROOT CAUSE =====================
Caused by: org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “input”
@mo3azfadel A drop-down list is based on the tag being a select. You have a div as the tag (your first Value). That won’t work. Does the actual element have the down arrow in the textbox area? Just trying to figure out if it is a Search box as compared to a Drop-down.
If you are using the Web Spy to “collect” the properties, then you need to highlight the actual drop-down to get the proper attributes. Also, the Selected Locator you have in your image above looks very fragile for any change.
Maybe show some HTML and we can give you more information to assist.
@grylion54 Many thanks for your replay
Yes the element have the down arrow , i highlighted the actual drop-down again and i found that it`s with input tag
Okay, so with the “type” as Search and “tag” as input, you cannot use the Select drop-down methods. On our pages, you have to start typing a phrase into the textbox and then the Search’s drop-down effect displays a listing. If you Inspect the HTML of the drop-down list (the items that display in the drop-down, not the textbox), then you can create a reference to the first item of the list. In the case below, I created h4_Client Search.
WebUI.click(findTestObject('my Page/input_Client'))
// throw in the name we will be searching for
WebUI.setText(findTestObject('my Page/input_Client'), GlobalVariable.ClientName)
// wait until get search result back
WebUI.waitForElementVisible(findTestObject('my Page/h4_Client Search'), 10)
WebUI.click(findTestObject('my Page/h4_Client Search'))
WebUI.delay(1)
Another way you could select the first item would be to use WebUI.clickOffset(findTestObject('my Page/input_Client'), 40, 45)
A Random Selection
This will select a random item from the Search list below the textbox (but I used the HTML of the Search items to create an xpath):
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import java.util.Random
Random rand = new Random();
WebUI.click(findTestObject('my Page/input_Client'))
WebUI.setText(findTestObject('my Page/input_Client'), "Grylion")
WebUI.delay(2)
'To locate rows of table it will capture all the rows available in the table'
rows_table = DriverFactory.getWebDriver().findElements(By.xpath('//div[@class="selector-options-item"]'));
WebUI.comment("Number of items: " + rows_table.size())
upperLimit = rows_table.size();
rows_table.get(rand.nextInt(upperLimit)).click();
@grylion54 unfortunately this solution didn`t work , can we have a quick meeting to solve this together ?
Including the click offset?
WebUI.clickOffset(findTestObject('my Page/input_Client'), 40, 45)
1 Like