public void selectOption ( String option ) { String action = SELECTING + option + " in " + prettyOutput ( ) ; String expected = prettyOutputStart ( ) + PRESENT_DISPLAYED_AND_ENABLED + option + SELECTED ; try { if ( isNotPresentDisplayedEnabledSelect ( action , expected ) ) { return ; } // ensure the option exists if ( ! Arrays . asList ( get . selectOptions ( ) ) . contains ( option ) ) { reporter . fail ( action , expected , CANT_SELECT + option + " in " + prettyOutput ( ) + " as that option isn't present. Available options are:<i><br/>&nbsp;&nbsp;&nbsp;" + String . join ( "<br/>&nbsp;&nbsp;&nbsp;" , get . selectOptions ( ) ) + "</i>" ) ; return ; } // do the select WebElement webElement = getWebElement ( ) ; Select dropdown = new Select ( webElement ) ; dropdown . selectByVisibleText ( option ) ; } catch ( Exception e ) { log . warn ( e ) ; reporter . fail ( action , expected , CANT_SELECT + prettyOutputEnd ( ) + e . getMessage ( ) ) ; return ; } reporter . pass ( action , expected , "Selected <b>" + option + INN + prettyOutputEnd ( ) . trim ( ) ) ; }
Selects the option from the dropdown matching the provided value but only if the element is present displayed enabled and an input . If those conditions are not met the select action will be logged but skipped and the test will continue .