Unable to Select an option from the dropdown : Error : Element should have been "select" but was "div"

Hello Everyone,

I am having problem with not new issue but this is bothering that I wanted to select arbitrary text value from the dropdown and getting an error that : Element should have been “select” but was “div”

I have tried via xpath and later spyWeb also with predefined keywords SelectOption from Value,Label

Some help in this regard would be highly appreciated.

Following is the Log, Please do have a look.

2020-07-13 14:36:32.238 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-07-13 14:36:32.238 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/Web UI/Basic Tests/Devices/Register_and_Verify_New_Device
2020-07-13 14:36:32.590 DEBUG testcase.Register_and_Verify_New_Device - 1: random = RandomStringUtils.random(5, true, true)
2020-07-13 14:36:32.592 DEBUG testcase.Register_and_Verify_New_Device - 2: callTestCase(findTestCase(“Web UI/Basic Tests/Log In/Log In to . Portal”), [:], STOP_ON_FAILURE)
2020-07-13 14:36:32.763 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-07-13 14:36:32.764 INFO c.k.katalon.core.main.TestCaseExecutor - CALL Test Cases/Web UI/Basic Tests/Log In/Log In to . Portal
2020-07-13 14:36:33.082 INFO c.k.k.core.webui.driver.DriverFactory - Starting ‘Chrome’ driver
Jul 13, 2020 2:36:33 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using new ChromeOptions() is preferred to DesiredCapabilities.chrome()
2020-07-13 14:36:33.113 INFO c.k.k.core.webui.driver.DriverFactory - Action delay is set to 0 milliseconds
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 10827
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jul 13, 2020 2:36:35 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
2020-07-13 14:36:35.942 INFO c.k.k.core.webui.driver.DriverFactory - sessionId = 52d79b8c67197e512ec35c9fa3a0fbae
2020-07-13 14:36:35.956 INFO c.k.k.core.webui.driver.DriverFactory - browser = Chrome 83.0.4103.116
2020-07-13 14:36:35.956 INFO c.k.k.core.webui.driver.DriverFactory - platform = Windows 10
2020-07-13 14:36:35.957 INFO c.k.k.core.webui.driver.DriverFactory - seleniumVersion = 3.141.59
2020-07-13 14:36:35.957 INFO c.k.k.core.webui.driver.DriverFactory - proxyInformation = ProxyInformation { proxyOption=NO_PROXY, proxyServerType=HTTP, username=, password=********, proxyServerAddress=, proxyServerPort=0, executionList="", isApplyToDesiredCapabilities=true }
2020-07-13 14:36:36.620 DEBUG testcase.Log In to . Portal - 2: delay(2)
2020-07-13 14:36:38.632 DEBUG testcase.Log In to . Portal - 3: setText(findTestObject(“Web UI Core Objects/Log In/User Name Text Field”), “XXX”)
2020-07-13 14:36:39.245 DEBUG testcase.Log In to . Portal - 4: setText(findTestObject(“Web UI Core Objects/Log In/Password Text Field”), “XXX”)
2020-07-13 14:36:39.866 DEBUG testcase.Log In to . Portal - 5: click(findTestObject(“Web UI Core Objects/Log In/Sign In”))
2020-07-13 14:36:40.182 DEBUG testcase.Log In to . Portal - 6: delay(1)
2020-07-13 14:36:41.185 INFO c.k.katalon.core.main.TestCaseExecutor - END CALL Test Cases/Web UI/Basic Tests/Log In/Log In to Portal
2020-07-13 14:36:41.186 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-07-13 14:36:41.190 DEBUG testcase.Register_and_Verify_New_Device - 3: maximizeWindow()
2020-07-13 14:36:42.475 DEBUG testcase.Register_and_Verify_New_Device - 4: delay(2)
2020-07-13 14:36:44.477 DEBUG testcase.Register_and_Verify_New_Device - 5: click(findTestObject(“Web UI Core Objects/Management/Organizations/Organizations_Link”))
2020-07-13 14:36:44.841 DEBUG testcase.Register_and_Verify_New_Device - 6: delay(1)
2020-07-13 14:36:45.846 DEBUG testcase.Register_and_Verify_New_Device - 7: click(findTestObject(“Web UI Core Objects/Management/Organizations/Create_New_Organization_Link”))
2020-07-13 14:36:46.253 DEBUG testcase.Register_and_Verify_New_Device - 8: delay(1)
2020-07-13 14:36:47.258 DEBUG testcase.Register_and_Verify_New_Device - 9: setText(findTestObject(“Web UI Core Objects/Management/Organizations/Create_New_Organization_Text_Field”), “Test” + random)
2020-07-13 14:36:47.928 DEBUG testcase.Register_and_Verify_New_Device - 10: click(findTestObject(“Web UI Core Objects/Management/Organizations/Create_New_Organization_Save_Btn”))
2020-07-13 14:36:48.268 DEBUG testcase.Register_and_Verify_New_Device - 11: delay(4)
2020-07-13 14:36:52.273 DEBUG testcase.Register_and_Verify_New_Device - 12: randomString = RandomStringUtils.random(5, true, true)
2020-07-13 14:36:52.275 DEBUG testcase.Register_and_Verify_New_Device - 13: click(findTestObject(“Web UI Core Objects/Management/xyz_ C_./xyz_C_.s_Link”))
2020-07-13 14:36:52.651 DEBUG testcase.Register_and_Verify_New_Device - 14: click(findTestObject(“Web UI Core Objects/Management/xyz_ C_./Register_New_Device/Page_XXx . Portal/span_Register device”))
2020-07-13 14:36:53.720 DEBUG testcase.Register_and_Verify_New_Device - 15: setText(findTestObject(“Web UI Core Objects/Management/xyz_ C_./Register_New_Device/Reg_Code_Text_Field”), “w4kSnRAPDe”)
2020-07-13 14:36:54.814 DEBUG testcase.Register_and_Verify_New_Device - 16: click(findTestObject(“Web UI Core Objects/Management/xyz_ C_./Register_New_Device/Reg_Code_Nxt_Btn”))
2020-07-13 14:36:55.379 DEBUG testcase.Register_and_Verify_New_Device - 17: selectOptionByLabel(findTestObject(“Web UI Core Objects/Management/xyz_ C_./Register_New_Device/div_Test-xyz”), “Test” + random, false)
2020-07-13 14:36:56.424 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to select option by label ‘TestZbJl8’ of object ‘Object Repository/Web UI Core Objects/Management/xyz_ C_./Register_New_Device/div_Test-xyz’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to select option by label ‘TestZbJl8’ of object ‘Object Repository/Web UI Core Objects/Management/xyz_ C_./Register_New_Device/div_Test-xyz’
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.SelectOptionByLabelKeyword.selectOptionByLabel(SelectOptionByLabelKeyword.groovy:98)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword.execute(SelectOptionByLabelKeyword.groovy:71)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByLabel(WebUiBuiltInKeywords.groovy:1226)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$selectOptionByLabel$3.call(Unknown Source)
at Register_and_Verify_New_Device.run(Register_and_Verify_New_Device:61)
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.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 TempTestCase1594643790576.run(TempTestCase1594643790576.groovy:25)
Caused by: org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “div”
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘DE001-NB0329’, ip: ‘10.60.192.66’, 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:48)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword$selectOptionByLabel_closure1.doCall(SelectOptionByLabelKeyword.groovy:87)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword$selectOptionByLabel_closure1.call(SelectOptionByLabelKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword.selectOptionByLabel(SelectOptionByLabelKeyword.groovy:98)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword.execute(SelectOptionByLabelKeyword.groovy:71)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByLabel(WebUiBuiltInKeywords.groovy:1226)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$selectOptionByLabel$3.call(Unknown Source)
at Script1593784246776.run(Script1593784246776.groovy:61)
… 11 more
)
2020-07-13 14:36:56.426 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Web UI/Basic Tests/Devices/Register_and_Verify_New_Device FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to select option by label ‘TestZbJl8’ of object 'Object Repository/Web UI Core Objects/Management/xyz
C
./Register_New_Device/div_Test-xyz’
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.SelectOptionByLabelKeyword.selectOptionByLabel(SelectOptionByLabelKeyword.groovy:98)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword.execute(SelectOptionByLabelKeyword.groovy:71)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByLabel(WebUiBuiltInKeywords.groovy:1226)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$selectOptionByLabel$3.call(Unknown Source)
at Register_and_Verify_New_Device.run(Register_and_Verify_New_Device:61)
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.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 TempTestCase1594643790576.run(TempTestCase1594643790576.groovy:25)
Caused by: org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been “select” but was “div”
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘DE001-NB0329’, ip: ‘10.60.192.66’, 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:48)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword$_selectOptionByLabel_closure1.doCall(SelectOptionByLabelKeyword.groovy:87)
at com.kms.katalon.core.webui.keyword.builtin.SelectOptionByLabelKeyword$_selectOptionByLabel_closure1.call(SelectOptionByLabelKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 17 more

2020-07-13 14:36:56.428 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/Web UI/Basic Tests/Devices/Register_and_Verify_New_Device

@kahmed You are using a command, selectOptionByLabel, which works on a select element but you have the tag of the element as a div, div_Test-xyz.

If you are using the Spy to get your information, then use it again and make sure you only have the drop-down highlighted–the actual element only. If you know how to review the source code and create an XPath for your select element, then that’s what you need now. If you need assistance, then put some HTML of the object here for us to better assist you. (For Chrome, hit F12 then right click on your element and choose Inspect.)

Posting solution to help other people:

List devices = driver.findElements(By.cssSelector/Xpath(’.class name’))

for (WebElement Dev : devices) {
println(Dev.getText())

println(Dev)

if (Dev.getText().equals('Test' + random)) {
    Dev.click()

    break
}

}

You are trying to perform operation on Dropdown using “select”

when you use Select in script, you are providing locator to the wrong tag i.e not to the “select” Tag but to “div” Tag.

Select drpdwn=new Select(driver.findElement(By.id(“idpointingtowrongtag")));

If you are beginner watch below video for more clarity https://youtu.be/jKT6OAwcc0c