Why don't you move this check at the beginning? if pageElement ... then the method does something....