0

on website I have sometimes additional button with restoring autosaved data filled in the form, which pops in random moments (sometimes someone tests something and close form, which causing the popup button). I tried with Continue if element is not visible in protractor with following code:

let DoNotRefillBtn=element.all(by.className('modal-button-no'));
    var isApproachable = function(element) {
        return element.isPresent().then(function (present) {
            return present
                ? element.isDisplayed()
                : false;
        });
    };

describe(...)
    it('Open the form:', function () {
            browser.driver.get('foo');
            browser.sleep(1000);
            isApproachable(DoNotRefillBtn).then(function(approachable) {
                if (approachable) {
                    DoNotRefillBtn.click();
                    browser.sleep(500);
                }
                else {
                    browser.sleep(300);
                }
            });

It clicks correctly, but after clicking, it throws error Failed: element not visible on line DoNotRefillBtn.click();.

Why does the program clicks and throws an error that thing is not clickable (after it was clicked)?

Michal
  • 443
  • 1
  • 10
  • 25
  • I'm not sure, but `return present ? element.isDisplayed() : false;` looks smelly. It returns either `` or `boolean`. – Kacper Jan 04 '18 at 09:16
  • I have this from this issue: https://stackoverflow.com/questions/36201154/continue-if-element-is-not-visible-in-protractor and returns boolean – Michal Jan 04 '18 at 09:29

1 Answers1

0

I used a workaround, the button comes with the status message "Do you want to refill the form?". So when I check for the status message and click the button, seems to be working:

let StatusMessage=element.all(by.className('status-message'));
let DoNotRefillBtn=element.all(by.className('modal-button-no'));
var isApproachable = function(element) {
   return element.isPresent().then(function (present) {
      return present
        ? element.isDisplayed()
          : false;
    });
};

describe(...)
it('Open the form:', function () {
        browser.driver.get('foo');
        browser.sleep(1000);
        isApproachable(StatusMessage.get(8)).then(function(approachable) {
                if (approachable) {
                    DoNotRefillBtn.get(0).click();
                    browser.sleep(500);
                }
            });
    });
});

StatusMessage.get(8) is 8 because there are some more messages with the same class, but not displayed. I counted which status-message is that one and it seems to be working - closes popup if displayed, but skipping when it's not.

Propably checking the button and clicking it gives some problems

Michal
  • 443
  • 1
  • 10
  • 25