Need help on try-catch

Viewed 9352

I am trying to use try-catch block in my protractor test, please see the code below:

try {
    element(by.id('usernameas')).sendKeys(data);
}
catch(err) {
    console.log('error occured');
} 

I am deliberately passing wrong locator to check whether it is going in catch block or not, currently it is giving me error NoSuchElementError on command prompt and test execution stops rather than going into catch block.

Please suggest.

2 Answers
Related