public boolean isTextSelectedInDropDown ( final By by , final String displayText ) { WebElement element = driver . findElement ( by ) ; List < WebElement > options = element . findElements ( By . xpath ( ".//option[normalize-space(.) = " + escapeQuotes ( displayText ) + "]" ) ) ; for ( WebElement opt : options ) { if ( opt . isSelected ( ) ) { return true ; } } return false ; }
Checks if a text is selected in a drop down list . This will consider the display text not the actual value .