Selecting information from a dynamic dropdown

Hi all,

I have been looking for the past 2 weeks, on and off, and I haven’t found any information on this. I was wondering how, if at all possible, one would select an option in a dropdown that is dynamic (It is an address dropdown that is generated by a lookup when a post/zip code is entered) using data-driven testing. I have tried the selectOptionByValue tag and have had no success (mostly because it’s probably the wrong tag to be using). I have also tried selectOptionByValue this also did not work. Although I could probably do it with selectOptionByIndex, this would require a lot of manual work and it is this I am attempting to avoid. Any help with this would be greatly appreciated.

Just for reference the message it fails with is:
2020-01-27 09:59:40.572 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/user account input FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: row for class: Script1578992957925

Thanks in advance

It’s possibly a custom javascript dropdown and not a real select box? Do an inspect in Chrome after you’ve typed something to see what the HTML looks like when the autocomplete has generates the possible values.

Hi, thanks for the reply, what exactly am i looking for? I am pretty sure it is a custom javascript dropdown, would that mean that it wouldn’t be possible to select from it?

Yeah you can probably, but you’ll need a different testobject to click on

First, learn how to use DevTools to identify the HTML elements used by your “dropdown”. There is no HTML element actually called “dropdown”, hence the quotes.

Don’t let JavaScript cloud the issue. First find out the HTML being used.

No. If a user can do it, an automation user (Katalon) can do it.

<div class="dropdown-menu open" role="combobox" style="max-height: 462.766px; overflow: hidden; min-height: 107px;">
<ul class="dropdown-menu inner" role="listbox" aria-expanded="true" style="max-height: 450.766px; overflow-y: auto; min-height: 95px;">
<li data-original-index="1" class="selected">
<a tabindex="0" class="residential" data-tokens="null" role="option" aria-disabled="false" aria-selected="true">
<span class="text">121 MIDDLETON ROAD, HACKNEY, LONDON, E8 4LL</span><span class="glyphicon glyphicon-ok check-mark"></span></a></li>

This is the first lines of the html from the dropdown i want to select from the text that is visually shown. which is in the final row, I have no clue what selector I should be using.

Use the recorder or make an xpath like:

//*[@class=“dropdown-menu open”]//li[@data-original-index=“1”]//span[@class=“text”]

or if you know which text will appear something like:

//*[@class=“dropdown-menu open”]//span[contains(text(),‘121 MIDDLETON ROAD’)]

All the different addresses im looking for hav different indecies so im not sure the first one would work, as for the second one, the actual text I have but it is being drawn from a data sheet, im not sure that xpath would work for me…

Well, then make the TestObject parameterized, for example you can do:

//*[@class=“dropdown-menu open”]//span[contains(text(),‘${expectedValue}’)]

and then get the testobject:

findTestObject(‘Object Repository/TheTestObject’, [‘expectedValue’: ‘121 MIDDLETON ROAD’])

and the next one for example:

findTestObject(‘Object Repository/TheTestObject’, [‘expectedValue’: ‘ANOTHER NICE ROAD’])

etc.

I am trying to parameterise the test object my xpath when i right click on the first item in the list is:
/html/body/div[1]/div[2]/div/div/form/div[4]/div[2]/div/div/div/ul/li[1]/a/span[1]
however with the li[1]/a/span[1] is throwing me off, because they determine which section it is selecting from. not all the addresses are in li[1]. I need some advice thanks.

With your xpath: html/body/div[1]/div[2]/div/div/form/div[4]/div[2]/div/div/div/ul/li[1]/a/span[1] it will not work, read the latest answer you got from r.klein1 again, i think the solution to your problem is in there.

I think the fundamental problem here is that, given an element with a specific dynamic property (meaning there is something about that element that is not constant on every test execution), how would one use Katalon to operate (click, etc) on such an element.

@r.klein1’s latest answer essentially is the correct approach, which is to use a variable to represent what is dynamic inside a Test Object’s locator - this usage of variables in Test Object is called parameterizing Test Objects.
https://docs.katalon.com/katalon-studio/docs/parameterize-web-test-object-properties.html

So, the Test Object will have this as the Selected locator

Notice that there is a ${} surrounded the expectedValue. This syntax will let Katalon knows that expectedValue is a variable. Then you would use this Test Object in a test case like this:

// Preceding steps
WebUI.click(findTestObject('path to that Test Object', ['expectedValue': '121 MIDDLETON ROAD']));

So this allows you to essentially compute expectedValue during the execution. Something like this, assuming that you compute the value using data driven testing:

WebUI.click(findTestObject('path to that Test Object', ['expectedValue': actualExpectedValue]));

Where actualExpectedValue is a Test Case variable that eventually will receive the look-up value from your Test Data.

A fair question may be how to come up with this locator:

You can use the Web Recorder to click on the object and see from the list of generated XPaths, or you can write one directly from the HTML if you are experienced.

The above example uses the click, but I think the same principle goes with selectOptionByValue. Let us know what you have tried through your test script and full log, because this:

is not very informative without the current Test Script.

I tried using the webselector and it comes back with //form[@id=‘create_account_form’]/div[4]/div[2]/div/div/div/ul/li[9]/a for example, this “li[9]” is where I need to perameterise the test object as it is describing the item number in the list. Would li[contains(text(),‘$Address1’)] be correct or have I completely missed the point there.

The error is somewhat unrelated tbh, I was using the wrong command mostly out of curiosity/investigation as I had no clue what I needed to do to get this to work.

The only thing that might cause an issue here is that I dont have the full exact return that my list will give but I do have enough that any person would be able to recognise it and in a format that is identical to the first half of what would be in the list.

That looks correct, I think you are heading to the right direction. The next question is that, can you provide the value of Address1, or compute it from what you have ?

Please elaborate on this.

Address1 is setup as a variable in the variables section of my test case and is fed by a data sheet with a column title of Address1 so I assume that this should fill properly as all my other variables have been working fine, it was just this one.

For example i have an entry of “Flat A, 183 Amhurst Road” what the list will populate with is “FLAT A, 183 AMHURST ROAD, HACKNEY, LONDON, E8 2AW” is what i have enough for katalon to be able to select it from the list

I think yes, so since the actual rendered value is all upercase, you can do it like this:

var actualAddress = Address1.toUperCase()
// Using the actualAddress here

Please try to see if it works. The contain() function in li[contains(text(),’$Address1’)] should be able to search for an element which contains the text that you pass in.

This particular command is not working it is giving me this error:

2020-01-29 15:36:14.137 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/user account input FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: Script1578992957925.var() is applicable for argument types: (java.lang.String) values: [17 MENDIP COURT]
Possible solutions: wait(), run(), run(), every(), any(), wait(long)
	at user account input.run(user account input:19)
	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:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1580312165464.run(TempTestSuite1580312165464.groovy:36)

The parameterised test object is failing with this error when i remove the previous command:

2020-01-29 15:31:57.087 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Unable to click on object 'Object Repository/Page_Southwark/address_select' (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to click on object 'Object Repository/Page_Southwark/address_select'
	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.ClickKeyword.click(ClickKeyword.groovy:79)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:42)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$3.call(Unknown Source)
	at user account input.run(user account input:64)
	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:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1580311838508.run(TempTestSuite1580311838508.groovy:36)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/Page_Southwark/address_select' located by 'By.xpath: //form[@id='create_account_form']/div[4]/div[2]/div/div/div/ul/li[contains(text(),‘Address1’)]/a' not found
	at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1113)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:52)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.call(ClickKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.click(ClickKeyword.groovy:79)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:42)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$3.call(Unknown Source)
	at Script1578992957925.run(Script1578992957925.groovy:64)
	... 13 more
)
2020-01-29 15:31:57.094 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/user account input FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to click on object 'Object Repository/Page_Southwark/address_select'
	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.ClickKeyword.click(ClickKeyword.groovy:79)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword.execute(ClickKeyword.groovy:42)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click(WebUiBuiltInKeywords.groovy:616)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$click$3.call(Unknown Source)
	at user account input.run(user account input:64)
	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:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:169)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1580311838508.run(TempTestSuite1580311838508.groovy:36)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/Page_Southwark/address_select' located by 'By.xpath: //form[@id='create_account_form']/div[4]/div[2]/div/div/div/ul/li[contains(text(),‘Address1’)]/a' not found
	at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1113)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
	at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.doCall(ClickKeyword.groovy:52)
	at com.kms.katalon.core.webui.keyword.builtin.ClickKeyword$_click_closure1.call(ClickKeyword.groovy)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
	... 19 more

Ah,

Try something like this:

String Address1Str = Address1
Address1Str = Address1Str.toUpperCase();
// Use Address1Str instead of Address1 here

This code essentially “converts” Address1 to type string, which toUpperCase() method is available.
https://www.tutorialspoint.com/groovy/groovy_touppercase.htm

The Capitalisation command is working, but the parameterised test object is still throwing the same error, I dont know what to do next.

What is the error now ? Is it the object with the locator not being found, or something else ? Also, please share the current test script.