hungryhippos
hungryhippos

Reputation: 637

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?

Upvotes: 1

Views: 282

Answers (1)

hungryhippos
hungryhippos

Reputation: 637

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().

Upvotes: 1

Related Questions