Issue with selecting option from dropdown

HI
any other solution?

It’s is maybe a custom select that does not use “select” tag.
Can you show us all the HTML used for your dropdown using code inspector (F12) ? (and even the parent element)
Thank you

Hi @Antoine_Bulteau

here is the HTML for the same

Thank u

I can’t test this code, but you could create an object with xpath :

//select[@data-ng-model=‘vm.searchFilterID’]

And then use :

WebUI.selectOptionByValue(findTestObject(‘thisObject’), ‘Number’, false)

Hi

Tried the above solution and got this error

1

Did you checked the “Detect object by?” column on TestObject xpath definition ? Because it does not take anything into account here.

Yeah i checked it.

Creta

This is getting way out of hand… it’s not difficult to click a select/option element. I suspect we’re missing something and that can only mean you’ve missed telling us something. Yes, I know you’ve pasted a bunch of stuff in multiple posts but this is why it’s best to follow that advice we gave you earlier. It’s much easier for us to help you if you help us correctly in one post. I’ve been scrolling up and down here trying to see what hell is going wrong.

So. Enough.

What follows is my method of clicking Select Options. These use CSS selectors. I don’t do XPATH. Sorry. These are custom keyword methods. You know how to create them since you’re using clickUsingJS somewhere above.

import org.openqa.selenium.support.ui.Select
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

  void chooseSelectElementByText(String selector, String text) {
    WebUI.comment('chooseSelectElementByText "' + text + '"')
    WebDriver driver = DriverFactory.getWebDriver()
    Select sel = new Select(driver.findElement(By.cssSelector(selector)))
    sel.selectByVisibleText(text)
  }
  void chooseSelectElementByIndex(String selector, int index) {
    WebUI.comment('chooseSelectElementByIndex "' + index + '"')
    WebDriver driver = DriverFactory.getWebDriver()
    Select sel = new Select(driver.findElement(By.cssSelector(selector)))
    sel.selectByIndex(index)
  }

IF you’ve given us enough information to use the CSS available, this call should work:

chooseSelectElementByText("select[data-ng-model='searchFilterID']", "Number")

// OR...

CustomKeywords.'something.chooseSelectElementByText(...)

My preference is to make these static methods that I import as needed since then I don’t need all that “noise” created by CustomKeywords.‘whatever.whatever…’

Good luck.

You should also always use the ‘equals’ condition when using xpath locators. Right now it’s set to ‘contains’:

Please change this value to ‘equals’.

Hi Brandon_Hein

I tried changing into equals but not found the solution yet. I really don’t know whats wrong with this specific page dropdowns. I have used xpath for other dropdowns as well , it’s really working fine for me.

Hi

Thank you very much for your reply. Even i am wondering why such a small dropdown issue is not getting solved :(. i tried solution given by you and i am getting below error

Creta

Watch
My
Lips.

Show
Me
The
Code

Here is the Custom keyword code one you suggested in previous message.

package dropdown

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable

import org.openqa.selenium.support.ui.Select
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

public class Dropdown {

@Keyword
void chooseSelectElementByText(String selector, String text) {
	WebUI.comment('chooseSelectElementByText "' + text + '"')
	WebDriver driver = DriverFactory.getWebDriver()
	Select sel = new Select(driver.findElement('By.cssSelector(selector)'))
	sel.selectByVisibleText(text)
}
void chooseSelectElementByIndex(String selector, int index) {
	WebUI.comment('chooseSelectElementByIndex "' + index + '"')
	WebDriver driver = DriverFactory.getWebDriver()
	Select sel = new Select(driver.findElement('By.cssSelector(selector)'))
	sel.selectByIndex(index)
}

}

And this is my piece of script written

String None = WebUI.getText(findTestObject(‘New changes/Vendor/Number’))

    GlobalVariable.Page2 = None

    WebUI.delay(2)

    WebUI.click(findTestObject('New changes/Vendor/button_Reset'))

    WebUI.waitForPageLoad(0)

    WebUI.delay(2)

    CustomKeywords.'dropdown.Dropdown.chooseSelectElementByText'('#searchForm > div.m-space > span > span > span.k-select > span', 
        'Number')

    not_run: WebUI.click(findTestObject('New changes/Vendor/Page_Nexgen AM/Select'))

I really REALLY am beginning to suspect you’re a troll. Sorry, but that’s how it seems.

Spot the difference.

When you can’t even copy-paste code you MUST be trying to wind us up. :rage:

I said “Enough” before? Well now I’m done here. If anyone else wants to continue, that’s their call.

Hi @Russ_Thomas

I am not a troll. I am a student who is really interested in learning katalon tool. And i do agree i am not good at coding because i am still learning things. I copied the code given by you but it showed me an error. Please see an attachment.

Thank you

You didn’t, not in the Ctrl-C sense, anyway.

This… 'By.cssSelector(selector)' != By.cssSelector(selector)

The underlined terms are because I left out an import statement. It happens. Since you’re trying to learn this stuff, treat it as “homework” to go find out what I forgot to import and make a post correcting my error.

How else do we find out if a student has been paying attention? Homework.

Hi @Russ_Thomas

Done with home work and here is the missing import:).

And now given script is fine. When i run the test, it showed me error something like this

I copied the CSS selector using Inspector(F12) for that specific dropdown

And My Script written is here
if (WebUI.verifyElementVisible(findTestObject(‘New changes/Vendor/a_2’), FailureHandling.OPTIONAL)) {
WebUI.delay(1)

    WebUI.click(findTestObject('New changes/Vendor/a_2'))

    WebUI.waitForPageLoad(0)

    WebUI.delay(1)

    WebUI.verifyElementPresent(findTestObject('New changes/Vendor/Number list'), 0)

    String None = WebUI.getText(findTestObject('New changes/Vendor/Number'))

    GlobalVariable.Page2 = None

    WebUI.delay(2)

    WebUI.click(findTestObject('New changes/Vendor/button_Reset'))

    WebUI.waitForPageLoad(0)

    WebUI.delay(2)

    CustomKeywords.'dropdown.Dropdown.chooseSelectElementByText'('#searchForm > div.m-space > span > span > span.k-select > span', 
        'Number')

    not_run: WebUI.click(findTestObject('New changes/Vendor/Page_Nexgen AM/Select'))

    not_run: WebUI.delay(2)

Thank you

So, you have a SPAN element, not a SELECT element. You cannot therefore use a SELECT API on a SPAN. Not only that, a SPAN does not contain OPTION elements.

I’ll say two things here:

  1. This whole thread is a travesty of what we normally do so well. I’m sorry for my part in that.
  2. You, creta, played your part too but you did at least post enough information (eventually) for the penny to drop for the rest of us. My apologies to you for my part in this mess.

Here was the first clue:

And shortly after, this is where I believe things went astray:

selectOptionByValue MUST be used on a SELECT element (not a span).

Later, you posted this, creta:

1

Which quite clearly tells you (all of us) what is going wrong. My bad. I missed that (or I was so dismissive I didn’t see what was right there in front of me).

And don’t think I’m blaming Antoine - far from it. He later posted this:

My bad again. I missed that. Sorry.

So, creta, start again. You need a series of clicks on the correct elements, NONE OF WHICH ARE SELECT ELEMENTS, probably with small delays between each click to give the UI time to display the dropdown. I hope that’s clear?

As for this thread, I consider it “closed”. It’s a categoric disaster.

If you need more help, start another thread and make sure the words SELECT and OPTION are not mentioned again. But first, use SEARCH, there are many, many threads about targeting UL/LI and SPAN elements used as dropdowns.

1 Like

Oh, I forgot…

Top marks! Go to the head of the class! :clap:

Seriously, I hope you learned something along the way. :slight_smile:

2 Likes