How to select an option from this type of drop-down

How should i define the object in object repository

In pseudocode…

Click Element with ID "#selectRandom_1-selectized"
Wait for list to appear
Click item

It’s hard to advise on Click item because you didn’t show the HTML containing the items.

Note: selectRandom_1-selectized would seem to be populated going by the class names applied to the parent div: has-options full has-items

1 Like

Here is what I tried:
WebUI.click(findTestObject(‘Object Repository/Page_Adam Pettman App/div_Random Strings’))

HTML containing items:
image

Okay, so you can use CSS nth-child to select a specific item.

But first we need to find out why you can’t click on the dropdown. Did you wait until it was visible? Your error message does not contain any relevant info - it doesn’t say why it can’t click on it.

Note: there was an issue where errors were not being presented properly. Try upgrading to the latest release of Katalon.

Also, read this:

I’m not sure about this exact drop down. But I typically use select by value or id, would this work here for you?

https://docs.katalon.com/katalon-studio/docs/webui-select-option-by-value.html#example

Thank you for sharing it.

1 Like

I gave it a shot it was not working for me, not sure about the reason. Hence posted the query.

Let me know if you also want to give it a try.

hmmm, could you perhaps try to identify your object via xpath? it says object failed to click but not why, this is perhaps because it doesn’t like just the id? I mean looking at your html I do not see id at all. I do see “tabindex id” but not id.

Perhaps xpath like

//*div/input[@tabindex id = "selectRandom_1-selectized"]

I don’t know because I’ve not seen a space in attribute before.

Another option is if you right click and copy xpath and paste that perhaps I can help to write up an xpath for you? I believe this may possibly be why select by value does not work and clicking fails but doesn’t say why. I could be wrong though.

Can you share the entire error message (i.e. copy/paste it here)? There’s almost always a “Caused by” part of the error, but I cannot see the rest in your screenshot.

Here is what I did:

Recorded the script again and played it back after adding

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Page_Adam Pettman App/div_Random Strings (1)’), ‘Names’, false)

04-02-2019 09:13:50 PM Test Cases/Test_Generate Test Data

Elapsed time: 41.465s

Test Cases/Test_Generate Test Data FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to select option by value ‘Names’ of object ‘Object Repository/Page_Adam Pettman App/div_Random Strings (2)’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.selectOptionByValue(SelectOptionByValueKeyword.groovy:99)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.execute(SelectOptionByValueKeyword.groovy:71)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByValue(WebUiBuiltInKeywords.groovy:1138)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$selectOptionByValue$5.call(Unknown Source)
at Test_Generate Test Data.run(Test_Generate Test Data:34)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:331)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1554219826927.run(TempTestCase1554219826927.groovy:21)
Caused by: org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “div”
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘BNGECO-L-92289’, ip: ‘192.168.1.5’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: driver.version: unknown
at org.openqa.selenium.support.ui.Select.(Select.java:47)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword$_selectOptionByValue_closure1.doCall(SelectOptionByValueKeyword.groovy:87)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword$_selectOptionByValue_closure1.call(SelectOptionByValueKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.selectOptionByValue(SelectOptionByValueKeyword.groovy:99)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByValueKeyword.execute(SelectOptionByValueKeyword.groovy:71)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByValue(WebUiBuiltInKeywords.groovy:1138)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$selectOptionByValue$5.call(Unknown Source)
at Script1554130444713.run(Script1554130444713.groovy:34)
… 11 more

OR after recording

Now while doing playback it clicks on the dropdown, but unable to select other values from it

image

You cannot use the WebUI.selectOptionByValue() method on a non-<select> element (the element is a <div>).

From looking at your widget (looks like a custom widget, which is why you’ll need a custom solution), I would try the following approach first:

Locate and send keys to the <input> element:

So something like this might work:

WebUI.sendKeys(findTestObject('path/to/input/element'), 'Random Strings')

You may also need to send an ‘Enter’ keypress, but I would try without it first:

WebUI.sendKeys(findTestObject('path/to/input/element'), Keys.ENTER)

Let me know if that does the trick. If not, there’s other things to try :slight_smile:

1 Like

Thank you. Let me try.

Even I started scripting using sendkeys method. I hope it works now.

Thanks again

Sendkeys is also not working

04-02-2019 11:51:37 PM Test Cases/Test_Generate Test Data

Elapsed time: 50.303s

Test Cases/Test_Generate Test Data FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to send keys ‘’ to object ‘Object Repository/Generate_TestData/Page_Adam Pettman App/div_Random StringsRandom NumbersNamesSurnamesFull NamesPhone NumbersCredit Card NumbersAddressesEmail AddressesWebsitesUnique IDs’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:834)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$6.call(Unknown Source)
at Test_Generate Test Data.run(Test_Generate Test Data:45)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:331)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1554229293454.run(TempTestCase1554229293454.groovy:21)
Caused by: org.openqa.selenium.WebDriverException: unknown error: cannot focus element
(Session info: chrome=73.0.3683.86)
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘BNGECO-L-92289’, ip: ‘192.168.1.5’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.43.600210 (68dcf5eebde371…, userDataDir: C:\Users\ANKESH~1.SIN\AppDa…}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:50825}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 73.0.3683.86, webStorageEnabled: true}
Session ID: 5ab9b7394b6777034ca3fac3edf27afa
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at com.kms.katalon.selenium.driver.CChromeDriver.execute(CChromeDriver.java:20)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.doCall(SendKeysKeyword.groovy:53)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.call(SendKeysKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:834)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$6.call(Unknown Source)
at Script1554130444713.run(Script1554130444713.groovy:45)
… 11 more

Well, it’s effectively “invisible” (actually off-screen) so perhaps webdriver is refusing to deal with it.

@Brandon_Hein makes a good point - this is a custom control. Consequentially, most of us are going to be unfamiliar with its construction. I’m convinced there is more to this control than the HTML you’ve posted so far. But rather than chasing rabbits down a hundred rabbit holes…

  1. What does a user do when interacting with this control on this page? Please write out those steps in English, not in code. Make sure you describe every step clearly.
  2. What should happen next?

You’re probably going to say in answer to #1, “click on Full Names dropdown”. And if I got that right, here’s what I want you to do:

Right-click where the user would Left-click and send a screen shot of the devtools inspector window. Please don’t click around in the inspector - capture it exactly as it looks when you right click.

Do that again for every element you mention in #1 - wherever the user left-clicks, please right click and send the screen shot.

Think it might be this stuff:

1 Like

And this would appear to be the underlying JS library in use:

If it turns out that you are unable to automate this control, you have the option of setting a selection via the JavaScript API: setTextboxValue(str)

Caveat: This all relies on my having found the correct underlying library.

Nice find. Let me mess with this using Se and see what I can come up with.

1 Like

Interesting… The approach that I suggested originally works for that exact same widget type on https://selectize.github.io/selectize.js/

import org.openqa.selenium.By
import org.openqa.selenium.Keys
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser("https://selectize.github.io/selectize.js/");
WebDriver driver = DriverFactory.getWebDriver();
WebElement input = driver.findElement(By.xpath("//input[@id='select-beast-selectized']"));
input.sendKeys("Chuck Testa");
input.sendKeys(Keys.ENTER);

Maybe try doing it the way I’ve done above, i.e., skip using the WebUI methods altogether and just use Se directly.