-1

Protractor isDisplayed() method is failing with Timeout Error when object is not displayed on the page. Same issue exists with isPresent().

Below is the code snippet:

public async checkifelementisdisplayed(webElmntXpath: string) {
    let webElement = (element(by.xpath(webElmntXpath)));

    try {`enter code here`
         const eleStat = await webElement.isDisplayed(); //Tried with isPresent() as well
         console.log("element status is "+eleStat);

         if (eleStat) {
              return true;
         }
         else {
              return false;
         }
     } catch (e) {
         return false;
     }
}

Error: function timed out, ensure the promise resolves within 60000 milliseconds at Timeout._onTimeout (C:\UIAutomation\node_modules\cucumber\lib\user_code_runner.js:76:18) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)

Prasad
  • 119
  • 1
  • 5
  • 13

2 Answers2

0

you need to check if your page

  1. is angular
  2. is protractor ready

See these answers how to check https://stackoverflow.com/a/66111219/9150146

And a 1 min read answer about proper usage of isDisplayed https://stackoverflow.com/a/66110622/9150146

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
-1

Try adding await keyword for below line let webElement = await element(by.xpath(webElmntXpath));