1
this.BrandSetup = function (BrandName, URL, BrandDescription) {
    browser.isElementPresent(brandListingPagePo.box_AddNewBarnd).then(function (result) {
        if (result) {
            brandListingPagePo.box_AddNewBarnd.click();
        }
    }
}

I am calling this function three times for the first time it does not work maybe because of the (.then) promise is not resolved for the second and the third time it works fine.

Thanks in advance

tehbeardedone
  • 2,833
  • 1
  • 15
  • 23
  • 1
    The first time you run, your promise is probably just resolving to `false`. Try to [wait for the element](https://stackoverflow.com/questions/30205235/protractor-waiting-for-element-to-be-in-dom) first, then click. – Gunderson Mar 20 '18 at 16:27
  • Yeah, it worked but I needed to wait little more then expected @Gunderson then too would love to know how to wait for the promise to be resolve? – Vibhor Mathur Mar 21 '18 at 04:08
  • Use [wait](http://www.protractortest.org/#/api?view=webdriver.WebDriver.prototype.wait) - "The condition to wait on, defined as a promise, condition object, or a function to evaluate as a condition." – Gunderson Mar 21 '18 at 13:16

1 Answers1

0

What you're doing now doesn't work because it enters the function, sees that the element is not visible, then exits right away.

Use can use Protractor Expected Conditions to wait till the element is clickable before clicking it .

this.BrandSetup = function (BrandName, URL, BrandDescription) {
    const EC = protractor.ExpectedConditions;
    browser.wait(EC.elementToBeClickable(brandListingPagePo.box_AddNewBarnd)).then(function() {
        brandListingPagePo.box_AddNewBarnd.click();
    }
}
gawicks
  • 1,894
  • 15
  • 22