Select item List

hello,
@kazurayam @Russ_Thomas

i want to select one item in this dropdown list and i’m facing the error.

so i have tried select by (index, label, value) it does not work in the the classic method.

thank you for helping dears :upside_down_face:

UI:
image

html code :

script katalon:

error :

Your problem is this…

The <select> element is a hidden control (style=display:none). The application is hiding that control to present the same data using different HTML elements (probably a div element with span child elements). When you try to use selectElementBy*, the API is expecting to see a <select> element but you are providing the <span> element.

In short, you can’t use any of the selectElementBy* APIs. You need to use something else and, if needed, adjust your selectors accordingly.

@Russ_Thomas thank you very much for this observation.
I have tried some methods, but nothing works.
any suggestion so that i skip this step, which has been blocking me since 11 am.

:upside_down_face:

Simply put, you probably need to WebUI.click() the element directly. Try the same Text Object (i.e. the span).

the first click displays the list of items.
how to make the second click to select item?
i tried to capture an item with spy web, but it does not capture.

I need to see the HTML for the first screenshot…

The HTML you posted is for the hidden select element.

it’s the same HTML, i didn’t change it just crossed out the information

If you’re open to it, try using pure Selenium. You can get around element visibility pretty easily. A couple of ideas:

1.) Use the Select class:

WebElement element = WebUiCommonHelper.findWebElement(By.xpath("//select[@id='ct10_CONTENU_PAGE_DemandeComp_listeEntite']"), 30)
Select select = new Select(element)
// select by index, value, visible text, etc.:
select.selectByIndex(1)
select.selectByValue(13)
select.selectByVisibleText("...(AOF)")

2.) Send the value as keys to the <select> element (or an <input> element for the field, if it exists, which it looks like it might based on your screenshot, which has a search box). You then send a Keys.ENTER to set the field with the value you sent:

WebElement element = WebUiCommonHelper.findWebElement(By.xpath("//select[@id='ct10_CONTENU_PAGE_DemandeComp_listeEntite']"), 30)
element.sendKeys("...(AOF)")
element.sendKeys(Keys.ENTER)

Please what is the package i have to import ?
because when i run the test, even the browser not opened.

Press ctrl + shift + o on your keyboard.

script :

error :

Ah that’s right, it wants a stupid Test Object. I assume you have a Test Object already defined for that <select> element. If that’s true, then change the WebUiCommonHelper call to this:

WebElement element = WebUiCommonHelper.findWebElement(findTestObject("path/to/my/test/object"), 30)

or else, we could also use pure selenium:

WebElement element = DriverFactory.getWebDriver().findElement(By.xpath("//select[@id='ct10_CONTENU_PAGE_DemandeComp_listeEntite']"))

sorry, I haven’t been using Katalon for a while now…

1 Like

i don’t know what’s wrong again.

Can you share your Test Object for the element?

If you go back to using the old code, one thing I noticed is that you are trying to selectOptionByValue but your HTML shows your values are all numeric. You probably want to use selectOptionByLabel instead (the text you have blacked out); once you figure out what element to associate the drop-down to.

image

yourhtml

Ok, your problem here (and I think your problem originally) is that you are not targeting the <select> element, but rather some <span> element, like @Russ_Thomas mentioned above:

The Katalon (and, by extension, the Selenium) selectBy___() methods do not recognize <span>s, only <select>s.

In your test object, set the “Selection Method” to “Attributes”, and create a custom locator of type xpath with the following value:

//select[@id='ct10_CONTENU_PAGE_DemandeComp_listeEntite']

(Note: make sure you check the “Locate by” checkbox for the locator)

Then rerun your script.

The trick here, and the solution, is finding the correct form of words that will traverse the language barrier. None of which is the OP’s fault, but it’s a problem that rears its ugly head all too frequently.

@ferrariklersone Read my post again. Read @Brandon_Hein’s last post again. Everything you need is in there.

Good luck.

Thank you @Russ_Thomas @Brandon_Hein @grylion54
I applied your advice and followed your comments to the letter, and I was able to click on an item on the list.
legal notice to you :v:

1 Like