'Using scriptAll is not grabbing all values in dropdown

I am dipping my toes into Karate UI so please bear with me if I am missing something obvious here.

I am trying to grab all values under a specific dropdown and then trying to write a JS script to randomly pick one of them to run my test.

The dropdown html looks like:

<select class=id="CarId" name="CarId" aria-describedby="CarId-error" aria-invalid="false" xpath="1">
<option value="1">Mercedes</option>
<option value="2">BMW</option>
<option value="3">Lexus</option>
</select>

After some research, I found I can use scriptAll to grab all values so I used:

 * def getCars = scriptAll('#CarId', '_.textContent')

However, I keep returning an empty array when I do a karate.log on the getCars variable. Any ideas?



Solution 1:[1]

I figured it out, I had to first add a click() action on the #CarId element. I am assuming one can also get around this by using Select().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hungryhippos