Search code examples
ionic-frameworkprotractorappium

ion-option-button in protractor test - click not registered


I've got an ionic app, with an ionic-list with onionic-option-button. This button becomes visible when a user swipes to the left. I want to write a protractor (Chromedriver & Android & Appium & Protractor tests) test to swipe to the left, and click the button. The swipe is no problem, I can see the button becomes visible, but the click is not registered. The ion-option-button has an ng-click event that does trigger the event. I've tried:

  • Get the ion-option-button element and click it
  • Tried using tap instead
  • Tried to tap on the location, calculated by grabbing the ion-item (that contains the ion-option-button) and calculating where the ion-button-button is
  • Using tapAndHold, wait, and release
  • Used browser.driver.touchActions().tap(element)

I don't get any errors that the element is not clickable. The event is just not registered; so it looks like the ion-option-button listens to another event?

It works with Javascript:

browser.driver.executeScript('angular.element(document.getElementById("delete-button-0")).triggerHandler("click");');

Solution

  • After you make the swipe to the left action, try waiting for the element to be clickable:

    var EC = protractor.ExpectedConditions;
    var elm = element(by.id("delete-bu‌​tton-0"));
    
    browser.wait(EC.elementToBeClickable(elm), 5000);
    elm.click();  
    // or browser.actions().touchActions().tap(elm).perform();
    

    Or, you may need to move to the element and then click (or tap):

    browser.actions().mouseMove(elm).click().perform();
    

    You can also try scrolling into element's view before making a click/tap:

    browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
    

    And, only as a last resort and if everything else is not working, click it via javascript:

    browser.executeScript("arguments[0].click();", elm.getWebElement());
    

    There are drawbacks to this solution, make sure you understand the difference: