Forum Discussion

rezza's avatar
Occasional Contributor
3 years ago

How to select an option from selectBox

I can't select one of the options of the select box.
Actually, the select box opens when I run the test. But it doesn't select the option I want.
This is the function that I use in my stepDefinition:


    fun selectGender(gender: String?): UserProfileCompletionPage {
        clickOnTextFromDropdownList(selectBoxGender!!, gender!!)
        return UserProfileCompletionPage()



And this is the content of clickOnTextFromDropdownList function:


    fun clickOnTextFromDropdownList(list: WebElement, textToSearchFor: String) {
        val tempWait: Wait<WebDriver> = WebDriverWait(DriverFactory.driver, 30)
        try {
            println("Successfully sent the following keys: $textToSearchFor, to the following WebElement: <$list>")
        } catch (e: Exception) {
            println("Unable to send the following keys: $textToSearchFor, to the following WebElement: <$list>")
  "Unable to select the required text from the dropdown menu, Exception: " + e.message)



I'll be grateful if you guide me.
Thanks in advance.

No RepliesBe the first to reply