@ SuppressWarnings ( { "unchecked" } ) public static Component findByComponentType ( String id , String containerId , String componentType , int index , boolean required ) { java . awt . Container container = null ; if ( isBlank ( containerId ) ) { container = ( java . awt . Container ) currentWindow ( ) . getComponent ( ) . getSource ( ) ; } else { ComponentOperator op = componentMap . getComponent ( containerId ) ; if ( op != null && op . getSource ( ) instanceof java . awt . Container ) { container = ( java . awt . Container ) op . getSource ( ) ; } else { container = ( java . awt . Container ) findComponent ( containerId , currentWindow ( ) . getComponent ( ) . getSource ( ) ) ; if ( container == null ) { container = ( java . awt . Container ) currentWindow ( ) . getComponent ( ) . getSource ( ) ; } } } List < java . awt . Component > list = findComponents ( container , translateFindType ( componentType ) ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "findComponents returned list :" ) ; for ( java . awt . Component c : list ) { logger . debug ( " " + c . getName ( ) ) ; } logger . debug ( " index = " + index ) ; } if ( index < 0 || index >= list . size ( ) ) { if ( required ) { throw new JemmyDSLException ( "Component " + id + " not found" ) ; } else { componentMap . putComponent ( id , null ) ; logger . debug ( "findByComponentType returned null" ) ; return null ; } } java . awt . Component component = list . get ( index ) ; if ( component == null ) { if ( ! required ) { componentMap . putComponent ( id , null ) ; logger . debug ( "findByComponentType returned null" ) ; return null ; } else { throw new JemmyDSLException ( "Component " + id + " not found" ) ; } } JComponentOperator operator = convertFind ( component ) ; componentMap . putComponent ( id , operator ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "findByComponentType returned " + component ) ; } return convertFind ( operator ) ; }
Finds the first component with the given component type and stores it under the given id . The component can later be used on other commands using the locator id = ID_ASSIGNED . This method searches both VISIBLE and INVISIBLE components .