Select multiple values in drop-down list
Question ID: 105539
0
0

I’ve got a custom list object that is only seen as a WebElement. I want to be able to pass mutliple items to select all at one time and I’m not quite sure how to do this. I don’t want to have a separate step for each value in my script.

Marked as spam
Posted by (Questions: 89, Answers: 4)
Asked on July 29, 2014 1:08 pm
334 views
Answers (1)
1
Private answer

I've had to do something similar before and I have a function example that might help. You can use this a kind of template to build your own solution, but basically I used an array to split the list of values passed in through one argument and then created a loop to go through all the values. It's not a very difficult solution when you look at what is going on in the code

Function MultiList (obj, list_vals)

If obj = '''' or list_vals = '''' Then 'Check if values are blank
MultiList = False
Exit Function
End If

'Create an array to hold the list values that are comma delimited
list_array = Split (list_vals, '','')

'Create the scripting shell object to use the keyboard for input to select items and hit enter, which needs to be done after each list item select

Set Wsh = CreateObject(''Wscript.Shell'')

'Create a loop based on the number of list items passed in

list_limit = Ubound(list_array)

Browser(''Browser'').Page(''PageName'').WebElement(''WhateverList'').Click 'Put list object in focus to activate it

For i = 0 to list_limit
'The selection may be different depending on the behavior and you might need to adjust this.
'In my example, I use SendKeys operation, but this also would apply to Select on regular list objects or even Type

Wsh.SendKeys list_array(i)
Wsh.SendKeys ''{Enter}'' 'This could also use a Tab if needed depending on the object's behavior
Next

Set Wsh = Nothing
End Function

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on July 29, 2014 1:09 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top