How to select dynamic dropdown options in webapp

Hi,

In my app the dropdown values series always change dynamically. So I am not using selectOptionByIndex method to select options.

I am getting below exception , when I am trying to use selectOptionByLable or selectOptionByValue.

2019-03-11 16:28:06.444 e[1;31mERRORe[0;39m e[36mc.k.k.core.keyword.internal.KeywordMain -e[0;39m e[31m❌ Unable to select option by label ‘Agency as Participant (Content)’ of object ‘Object Repository/Page_Work Item/dropdown_Values’ (Root cause: org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was "coral-selectlist-item"e[0;39m
e[31mBuild info: version: ‘3.7.1’, revision: ‘8a0099a’, time: '2017-11-06T21:07:36.161Z’e[0;39m
e[31mSystem info: host: ‘01HW544044’, ip: ‘172.25.154.99’, os.name: ‘Windows 10’, os.arch: ‘x86’, os.version: ‘10.0’, java.version: '1.8.0_181’e[0;39m
e[31mDriver info: driver.version: unknown)e[0;39m
2019-03-11 16:28:06.447 e[1;31mERRORe[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[31m❌ selectOptionByLabel(findTestObject(“Page_Work Item/dropdown_Values”), “Agency as Participant (Content)”, false) FAILED.e[0;39m
e[31mReason:e[0;39m
e[31mcom.kms.katalon.core.exception.StepFailedException: Unable to select option by label ‘Agency as Participant (Content)’ of object ‘Object Repository/Page_Work Item/dropdown_Values’ (Root cause: org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was "coral-selectlist-item"e[0;39m
e[31mBuild info: version: ‘3.7.1’, revision: ‘8a0099a’, time: '2017-11-06T21:07:36.161Z’e[0;39m
e[31mSystem info: host: ‘01HW544044’, ip: ‘172.25.154.99’, os.name: ‘Windows 10’, os.arch: ‘x86’, os.version: ‘10.0’, java.version: '1.8.0_181’e[0;39m
e[31mDriver info: driver.version: unknown)e[0;39m
e[31m at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)e[0;39m
e[31m at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:65)e[0;39m
e[31m at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:27)e[0;39m
e[31m at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword.selectOptionByLabel(SelectOptionByLabelKeyword.groovy:98)e[0;39m
e[31m at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword.execute(SelectOptionByLabelKeyword.groovy:71)e[0;39m
e[31m at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)e[0;39m
e[31m at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByLabel(WebUiBuiltInKeywords.groovy:1200)e[0;39m
e[31m at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$selectOptionByLabel$3.call(Unknown Source)e[0;39m
e[31m at ContentOnly_Agency_Disapprove.run(ContentOnly_Agency_Disapprove:188)e[0;39m
e[31m at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)e[0;39m
e[31m at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)e[0;39m
e[31m at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)e[0;39m
e[31m at TempTestCase1552301857816.run(TempTestCase1552301857816.groovy:22)

Below is the code:

WebUI.click(findTestObject(‘Page_Work Item/Complete_Option’))

WebUI.delay(3)

WebUI.click(findTestObject(‘Page_Work Item/WorkItemdropdown’))

WebUI.delay(3)

not_run: WebUI.selectOptionByValue(findTestObject(‘Page_Work Item/dropdown_Values’), ‘973481821@content’, false)

not_run: WebUI.verifyOptionSelectedByValue(findTestObject(‘Page_Work Item/dropdown_Values’), ‘973481821@content’, false,
0)

WebUI.selectOptionByLabel(findTestObject(‘Page_Work Item/dropdown_Values’), ‘Agency as Participant (Content)’, false)

WebUI.verifyOptionSelectedByLabel(findTestObject(‘Page_Work Item/dropdown_Values’), ‘Agency as Participant (Content)’, false,
60)

Xpath of drodown_Values://*[@id=“coral-id-100”]

xpath for complete menu list : //[@id=“coral-id-100”]
for the individual item : //
[@id=“coral-id-100”]/coral-selectlist-item[3] -----this position number is changing.

WebUI screenshot:

Could some one please help me to resolve the issue.

That is because you are trying to use two APIs designed for HTML SELECT elements when in fact your elements are NOT select elements, they are custom elements called coral-selectList containing coral-selectList-item elements. You need to direct your tests toward these elements (using WebUI.click, etc) and avoid selectOptionBy* APIs.

1 Like

Thank you Thomas…

Now I am able to select the expected option by using WebUI.Click() instead of selectOptionBy*.

I have used dynamic Xpath : //*[@id=“coral-id-100”]/coral-selectlist-item[text()=’${myoption}’]

Issue was resolved.