protected setSelectValue()

in module/geb-core/src/main/groovy/geb/navigator/DefaultNavigator.groovy [967:1000]


    protected setSelectValue(WebElement element, value) {
        def select = new SelectFactory().createSelectFor(element)

        def multiple = select.multiple
        if (multiple) {
            select.deselectAll()
        }

        if (value == null || (value instanceof Collection && value.empty)) {
            if (multiple) {
                return
            }
            nonexistentSelectOptionSelected(value.toString(), select)
        }

        def valueStrings
        if (multiple) {
            valueStrings = (value instanceof Collection ? new LinkedList(value) : [value])*.toString()
        } else {
            valueStrings = [value.toString()]
        }

        for (valueString in valueStrings) {
            try {
                select.selectByValue(valueString)
            } catch (NoSuchElementException e1) {
                try {
                    select.selectByVisibleText(valueString)
                } catch (NoSuchElementException e2) {
                    nonexistentSelectOptionSelected(valueString, select)
                }
            }
        }
    }