Search code examples
node.jsappium

Appium - Received error undefined: Reference element is not defined


I don't know why it's giving me this error. I have just started the automation with appium/node.js

Can anyone help me out with this?

this.clickOnSavedCard.click();

const waitElemd = $('//android.widget.TextView[@resource-id="com.uat:id/changeSelectedPayment"]');
waitElemd.waitForDisplayed(12000);

driver.touchScroll({
  el: element,
  xOffset: 10,
  yOffset: 100
});

this.runCTA.click();

Solution

  • Looks like you are using WebdriverIO and faced the problem described here: webdriverio/issues/4172 It really depends on the Webdriverio version you are using. According to source code you can call it this way:

    driver.touchScroll(10, 110, <elementId>) // current master code
    

    or

    driver.touchScroll( <elementId>, 10, 110) // webdriverio v3.4
    

    Note that elementId is not a locator, but unique identifier that WebDriver assigns to a found element. So in order to get it, you first need to find an element with $. This is why you are getting an error: the incorrect argument is passed.

    Maybe you don't want to get elementId and later pass it to touchScroll(), so as doc suggested TouchAction can be used instead:

    driver.touchAction([ {action: 'press', x: startX, y: startY}, {action: 'moveTo', x: endX, y: endY}, 'release' ]);
    

    where startX,startY and endX,endY are coordinates that you would like to scroll from and to