0

I'm trying to look for an absence of an element in a conditional which would then take two different paths if the element is not there. However what I am getting is 'element not found' which is what I need but I need to go around this. Here is what I've tried:

if (HomeScreen.tabs.propertiesTab.isPresent()) {
  HomeScreen.tabs.propertiesTab.click();
} else {
  HomeScreen.tabs.allTabsTab.click().then(function() {
    HomeScreen.allTabs.properties.click();
  })
}

and

HomeScreen.tabs.propertiesTab.isPresent().toBeFalsy().then(function(isVisible) {
  if (isVisible) {
    HomeScreen.tabs.propertiesTab.click();
  } else {
    HomeScreen.tabs.allTabsTab.click().then(function() {
      HomeScreen.allTabs.properties.click();
    });

  }
});

Any suggestions?

Nicole Phillips
  • 753
  • 1
  • 18
  • 41

1 Answers1

1

Try to explicitly resolve the promise with then():

browser.isElementPresent(HomeScreen.tabs.propertiesTab).then(function (isPresent) {
    if (isPresent) {
        // ...
    } else {
        // ...
    }
});

Using browser.isElementPresent() here, but it should work with .isPresent() as well:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • This work however the element is present as I can see it and if I comment everything out and tell it to click it will click on it. I did a log of isPresent and it returns false. – Nicole Phillips Jul 08 '16 at 19:13
  • @NicolePhillips okay, are you sure you are locating the element correctly and there are no other elements matching the locator? – alecxe Jul 08 '16 at 19:15
  • Perhaps what I need is visibility of? – Nicole Phillips Jul 08 '16 at 19:24
  • @NicolePhillips if you need a wait, then probably - meaning, if the element is actually present, but not visible you might need `visibilityOf` or `invisibilityOf`. For presence/absence checks you can use `stalenessOf` or `presenceOf`. – alecxe Jul 08 '16 at 19:25