findElement error handling?
How would I go about clicking a button if it exists and ignoring it if it doesn't?
this.ptor.findElement(this.by.linkText('/logout'))
.then(function(element) {
element.click().then(callback);
})
isElementPresent won't do it for me, because I want to handle a case where the element is not present. Almost like
this.ptor.isElementNotPresent(someElement).then(callback);
Any sort of error handling on the promise? Any other way of doing this?
Error handler is within the then function:
this.ptor.findElement(this.by.linkText('/logout'))
.then(function(element) {
element.click().then(callback);
}
, function() {
callback()
});
I wish everyone just agreed on how to do promises.
I tried below code and it still it failing if element not found on the page, ptor.findElement(protractor.By.xpath('//*[@id="dLabel"]')).then(function(element) { element.click().then(callback); } , function() { callback() });
Use Try Catch block. Try the below code: 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'); });