I believe ‘value’ refers to the content of the field, not specifically a numerical value. The content of the field should be returned as a String whether there is a number or text data.
If that’s not the case, what behavior are you seeing when using value for your scenario?
Can you provide the HTML of the select element and associated options? It’s usually easier to provide a solution if we have the whole picture . Thanks.
Your object should have an xpath which looks like following to make sure your object is the one which is currently selected:
//select[@id=‘ddl’]//option[@selected=‘selected’]
The reason you are getting the text for ALL options under the select is that you are asking for the text of the ‘select’ element, which will grab ALL child text nodes beneath it (all of the texts of all of the ‘option’ elements). What you need is to get the text of ONLY the selected ‘option’ element. You do this either by creating a separate TestObject that locates the selected option (your xpath would look something like “//select[@id=’'ddl”]/option[@selected]"), or you do what Marek has suggested (and I would agree with).
I know that it’s convenient to try and stick with the WebUI methods already available to you, but you’re doing yourself a disservice by not utilizing the power of Custom Keywords.
I recently had to revisit this topic and came up with this:
String allBranchLocations = WebUI.getText(findTestObject('Dropdown Location'))
List allBranchesList=allBranchLocations.split("\\r?\\n") //Remove CRLF from each dropdown entry
String branchName=allBranchesList[0]
This converts the String to a List based on a Split for the CRLF of each entry from the dropdown.
The currently selected value in the dropdown is index[0]
It might help for this type of scenario