public void focus ( ) { String cantFocus = "Unable to focus on " ; String action = "Focusing on " + prettyOutput ( ) ; String expected = prettyOutputStart ( ) + " is present, displayed, and enabled to be focused" ; try { if ( isNotPresentDisplayedEnabledInput ( action , expected , cantFocus ) ) { return ; } WebElement webElement = getWebElement ( ) ; new Actions ( driver ) . moveToElement ( webElement ) . perform ( ) ; } catch ( Exception e ) { log . warn ( e ) ; reporter . fail ( action , expected , cantFocus + prettyOutputEnd ( ) + e . getMessage ( ) ) ; return ; } reporter . pass ( action , expected , "Focused on " + prettyOutputEnd ( ) . trim ( ) ) ; }
Focuses on the element but only if the element is present displayed enabled and an input . If those conditions are not met the focus action will be logged but skipped and the test will continue .