Jonathan Frias
Jonathan Frias

Reputation: 200

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

Upvotes: 4

Views: 5777

Answers (3)

Neal Jiang
Neal Jiang

Reputation: 1

U can see this

HTML Alt folk Chiptunes Electroclash G-Funk Hair metal

GOOVY
    $("form").artist = "1"         // first option selected by its value attribute
    $("form").artist = 2           // second option selected by its value attribute
    $("form").artist = "Ima Robot" // first option selected by its text

http://www.gebish.org/manual/0.9.2/navigator.html

Upvotes: 0

Sergey Ponomarev
Sergey Ponomarev

Reputation: 3191

Manual descibes it in section Setting Values

Upvotes: -1

BertVdBrande
BertVdBrande

Reputation: 126

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.

Upvotes: 11

Related Questions