Try it, Catch has the following syntax in Protractor. In the code below, you will first find the element using Id 'IdTextBoxCode'. Then the code to enter the code is 'codeTextBox.sendKeys (code);' located in the TRY block. If the code throws an exception (in this case, if the element with the Id 'IdTextBoxCode' is not found), it will go to the catch block and the error handling function.
browser.driver.findElement(by.id(browser.params.loginPage.IdTextBoxCode)).then(function(codeTextBox) { try { console.log("Entering Code: "+code); codeTextBox.sendKeys(code); } catch(err) { console.log('In catch block'); } }, function(err) { console.info('Code Text Box not displayed on page. Proceeding with default Code'); });
source share