Unable to select specific option from dropdown

Hi All,

I have a web application and One of our page consists Search and Sort dropdowns with a exact same options in it. Here when i try to select the option from search dropdown it actually selects option from sort dropdown.Some times it works but some times it doesn’t. So can anyone tell me how to select a specific option from dropdown? I had used “Selectoptionbyvalue” but here i have a “SPAN element” Not a “SELECT element”.Any other solution on this?

Here is the my Search dropdown UI looks like

image

And HTML for the same looks like

Awaitng for swift help!!
Thank you

Hi !
Your select seems to be under the span element. Did you try click on span then selectOptionByValue on select ?

Hi @HeleneB

I tried it but got an error. Please find below
image

My script is here

 WebUiBuiltInKeywords.delay(2)
WebUiBuiltInKeywords.click(findTestObject('Work order module/Search WO/Select dropdown'))

WebUiBuiltInKeywords.delay(2)

WebUiBuiltInKeywords.selectOptionByLabel(findTestObject('Work order module/Search WO/Select dropdown'), 'Class Name', 
    false)

WebUiBuiltInKeywords.delay(2)

Thank you

You click and select on the same object, but you have to create a new object for the select

1 Like

Yes like Helene said - your not actually selecting an option in your script - your just clicking on the drop down arrow again

1 Like

Hi

Can you show me how to create an object for select option?

Thank u

Try to capture the object with ObjectSpy.

Or right click on Object repository, and create a new Test Object.
Choose xpath in Selection Method, then on Selector editor, add

//select[@class=‘pure-u-1 ng-pristine ng-valid ng-touched’]

Save and call this new object for the selectOption step

I created the new test object Still facing some error:(

Test Object

My Script is here

WebUiBuiltInKeywords.delay(2)
WebUiBuiltInKeywords.click(findTestObject('Work order module/Search WO/Select dropdown'))

WebUiBuiltInKeywords.delay(2)

WebUiBuiltInKeywords.selectOptionByLabel(findTestObject('New changes/Asset Plan/Select Option'), 'Class Name', false)

WebUiBuiltInKeywords.delay(2)

And Error showing something like this.

Unable to select option by label ‘Class Name’ of object ‘Object Repository/New changes/Asset Plan/Select Option’ using regular expression (Root cause: org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression because of the following error:
SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘’ is not a valid XPath expression.
(Session info: chrome=72.0.3626.121)
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.17763 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: Selenium
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘D’, ip: ‘99’, os.name: 'Windows ', os.arch: ‘am’, os.version: ‘10.0’, java.version: ‘1’
Driver info: com.kms.katalon.core.webui.driver.ExistingRemoteWebDriver
Capabilities {javascriptEnabled: true, platform: ANY, platformName: ANY}
Session ID: e89b47ab505d8807ee9534cafd1e9472
*** Element info: {Using=xpath, value=})

Thank you

Use the spy web tool - it will be much easier for you

Capture the option in the drop down that you want to select - save the object - then place this object in here

WebUiBuiltInKeywords.selectOptionByLabel(findTestObject('New changes/Asset Plan/Select Option'), 'Class Name', false)
1 Like

Hi

I tried this before and it says "Element should have been “select” but was “li” Cause captured object tag is “li”.

This the captured object

Script is here

     WebUiBuiltInKeywords.delay(2)
WebUiBuiltInKeywords.click(findTestObject('Work order module/Search WO/Select dropdown'))

WebUiBuiltInKeywords.delay(2)

WebUiBuiltInKeywords.selectOptionByLabel(findTestObject('New changes/Asset Plan/li_Class Name'), 'Class Name', false)

WebUiBuiltInKeywords.delay(2)

Regards!

ok then change it from WebUI.selectOptioByLabel to WebUI.click - see how that works

Also if i were you, i would change the delay step to

WebUiBuiltInKeywords.waitForElementVisible(findTestObject('New changes/Asset Plan/li_Class Name'), 'Class Name', false)
2 Likes

Hi

It Worked for me!! Thank You:)

1 Like

How about if we have i dropdown list, but on my dropdown list we search first using text input then select?
#help

Raise a seperate topic with the behaviour your experiencing and ill take a look :slight_smile:

1 Like

Ohh I see, I think this same topic :slight_smile:

I have UI like this,

Reproduce:

  • When a user clicks the select group, it will have a dropdown list. But also have text input. the cursor direct to text input.

Hello guys,

I need help, I want to select an option but it fails to do so, because to select I do the following:

image

image

The message you give me is this:

Unable to find the element located by ‘By.xpath: //select[@id=‘ctl00_ContentPlaceHolder_NoAjax_ddType_ddControl’]’. Please recheck the objects properties to make sure the desired element is located.

Log:

Test Cases/New Test Case FAILED.

Reason:

com.kms.katalon.core.exception.StepFailedException: Unable to select option by label ‘NA’ of object ‘Object Repository/DropDownObjects/Page_P… G… S…/select_NADriver LogsFuel ReceiptLumber ReceiptManifestShort pay approvalTrip Envelope’ using regular expression

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:60)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.selectOptionByLabel(WebUiBuiltInKeywords.groovy:1200)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$selectOptionByLabel$5.call(Unknown Source)

at New Test Case.run(New Test Case:73)

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 TempTestCase1578509476326.run(TempTestCase1578509476326.groovy:23)

Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/DropDownObjects/Page_P… G… S…/select_NADriver LogsFuel ReceiptLumber ReceiptManifestShort pay approvalTrip Envelope’ located by ‘By.xpath: //select[@id=‘ctl00_ContentPlaceHolder_NoAjax_ddType_ddControl’]’ 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.SelectOptionByLabelKeyword$_selectOptionByLabel_closure1.doCall(SelectOptionByLabelKeyword.groovy:86)

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

Thanks!

HI

On many occasions it worked for me first to select the label corresponding to the drop-down list and then there is whether to display and select the option.

It is also good to note that the capture of objects is different when the recording method is used and when spy web is used

This only works when the <label> is associated with the actual <select> element using the for attribute. For example:

<label id="some_label" for="some_select">Label Text</label>
<select id="some_select">
    <option>Option 1 Text</option>
    .
    .
    .
</select>

If the <label> doesn’t have a for attribute that references the id of the associated <select>, then clicking on the label will do nothing.

2 posts were split to a new topic: Select option from dropdown