1

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");');
Boland
  • 1,454
  • 1
  • 12
  • 38
  • `browser.driver.touchActions().tap(element)` - did you call `perform()` at the end? – alecxe Feb 04 '16 at 19:52
  • Yes, thanks. Verified that, I do a perform(). – Boland Feb 04 '16 at 19:56
  • Just to check on the last statement, if you click via javascript (`executeScript`) - it works and the element is getting clicked - right? – alecxe Feb 04 '16 at 20:01
  • @alecxe I did not test that yet, but I just did. And yes, that is working: browser.driver.executeScript('angular.element(document.getElementById("delete-button-0")).triggerHandler("click");'); – Boland Feb 04 '16 at 20:22

1 Answers1

3

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:

Community
  • 1
  • 1
alecxe
  • 441,113
  • 110
  • 1,021
  • 1,148