Put a check like this and see if the reasons provided are really true:
if(element.style.visibility=="hidden" || element.style.display=="none" || element.disabled==true) {
} else {
element.focus();
}
If you still get the error, then use a 'try-catch' block and verify the same.