public static Condition selectedText ( final String expectedText ) { return new Condition ( "selectedText" ) { String actualResult = "" ; @ Override public boolean apply ( Driver driver , WebElement element ) { actualResult = driver . executeJavaScript ( "return arguments[0].value.substring(arguments[0].selectionStart, arguments[0].selectionEnd);" , element ) ; return actualResult . equals ( expectedText ) ; } @ Override public String actualValue ( Driver driver , WebElement element ) { return "'" + actualResult + "'" ; } @ Override public String toString ( ) { return name + " '" + expectedText + ' ' ; } } ; }
Checks for selected text on a given input web element