Unable to select specific option from dropdown


#1

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


#2

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


#3

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


#5

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


#6

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


#7

Hi

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

Thank u


#8

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


#9

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: http://seleniumhq.org/exceptions/invalid_selector_exception.html
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


#10

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)

#11

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!


#12

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)

#13

Hi

It Worked for me!! Thank You:)