Just like Selenium webdriver provides various Exception handling for Java, is there any way we can achieve same using Protractor.
If we want to handle element not fo
Try, Catch has the following syntax in Protractor. The below code will first find an element by Id 'IdTextBoxCode'. Then the code to enter code 'codeTextBox.sendKeys(code);' is in TRY block. If the code throws exception(in this case, if the element with Id 'IdTextBoxCode' is not found), then 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');
});