Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findElement error handling? #485

Closed
mavdi opened this issue Feb 3, 2014 · 3 comments
Closed

findElement error handling? #485

mavdi opened this issue Feb 3, 2014 · 3 comments

Comments

@mavdi
Copy link

mavdi commented Feb 3, 2014

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?

@mavdi
Copy link
Author

mavdi commented Feb 3, 2014

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.

@mavdi mavdi closed this as completed Feb 3, 2014
@smahalingam
Copy link

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()
});

@sakshisingla
Copy link

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');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants