1

When I am trying to check presence of not presented element/ button. I am getting:

Jasmine timeout exception

My code like

getName(): any {
    let name = element(by.id("xxxxxx"));
    return name.isPresent().then((ispresent) => {
        if (ispresent) {
            return name.getText();
        } else {
            return '';
        }
    })
}

I am trying to access that method expect(method).toequal('');

It should run, because if not present i am expecting empty string but i am getting Jasmine timeout.. I didn't added any waits any where.

2 Answers 2

1

isPresent()

From the GitHub repo, ElementFinder.isPresent

isPresent(): wdpromise.Promise<boolean> {
  return this.count().then((count) => {
    return count > 0;
  });
}

isPresent checks for a count, but does not catch if there is an error. If the count throws, we should probably return 0. Getting a text for an element that does not exist should also have throw a promise rejection.

Note: It might be better to change your method to async / await (optional).

async getName(): webdriver.promise.Promise<string> {
  const name = element(by.id("xxxxxx"));
  try {
    return name.getText();
  } catch (e) {
    return '';
  }
}

Or not async / await

getName(): webdriver.promise.Promise<string> {
  const name = element(by.id("xxxxxx"));
  return name.getText().catch(e) {
    return '';
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try the below one

async getName() {
    let name = element(by.id("xxxxxx"));
    let value: string = '';
    await name.ispresent().then((ispresent) => {
        if (ispresent) {
            value=name.getText();
        } 
    });
   return value;
}

Hope it helps you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.