Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select a combobox in geb with groovy

This is what I have currently with Geb. I want to be able to retrieve and set the value of a combobox (or drop down) in a page. I'm not quite sure how to do it, and the Book of Geb does not seem to cover this. This is the HTML element that I'm trying to work with.

<select style="height: 22px; width: 370px;" id="ddlContactTypes" name="ddlContactTypes">
                <option value="-1">--Please Select--</option>
                <option value="18">Customer Hauler</option>
                <option value="19">Customer General</option>
                <option value="20">Rolloff</option>
                <option value="21">Supplier</option>
                <option value="22">Leads</option>
                <option value="23">Competition</option>
                <option value="24">Employees</option>
                <option value="25">Customer Car</option>
                <option value="26">Secondary Metals Recycler</option>
                <option value="27">Mills</option>
                <option value="28">Brokerage Customers</option>
                <option value="29">Type Jon</option>
</select>

This is what I've go so far. This currently will click the element, but I don't know how to actually select one. Any ideas?

static content = {
  title {$("title")}
  contactType { $("#ddlContactTypes") }
}
def addUser(){
  contactType.click() 
}
like image 763
Jonathan Frias Avatar asked Dec 27 '22 13:12

Jonathan Frias


1 Answers

You can select an option by setting the value of the geb object :

contactType.value('20')

Above example will set the value to '20', making the list show 'Rolloff' as selected.

like image 80
BertVdBrande Avatar answered Jan 05 '23 01:01

BertVdBrande