Aggiungi semplicemente una condizione in and:
codice:
if (document.getElementById('prova') && document.getElementById('test')) {
   ...
}