CVS
CVS

Reputation: 13

Getting error in Appium that mobile:longClick is not implemented..is there another way?

I'm automating a native Android app using Java and Appium version 1.2.0. I want to automate long press on a row in a list to bring up some options that are accessible through long press, right now I test it manually. This is what I have tried:

     WebDriverWait wait = new WebDriverWait(driver, 30);
     HashMap<String,String> longtapObj= new HashMap<String,String>();
    WebElement elem = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.ListView[1]/android.widget.RelativeLayout[1]")));
    JavascriptExecutor js = (JavascriptExecutor) driver;        
    longtapObj.put("element", ( (RemoteWebElement) elem).getId()  );
     js.executeScript("mobile:longClick", longtapObj);

Appium server log error:

2014-09-02T23:29:45.808Z - debug: Request received with params: {"args":[{"element":"5"}],"script":"mobile:longClick"} 2014-09-02T23:29:45.810Z - debug: Responding to client that a method is not implemented

2014-09-02T23:29:45.810Z - info: <-- POST /wd/hub/session/f66d9550-c47e-4380-a0f4-c819a12f59a9/execute 501 3.656 ms - 158

2014-09-02T23:29:48.518Z - info: --> GET /wd/hub/status {}

Eclipse JUnit error:

org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 9 milliseconds

If a comment out the statement js.executeScript("mobile:longClick", longtapObj); no errors are thrown. Appreciate if anyone knows the right way to implement a log press using Appium in a native android app.

Upvotes: 1

Views: 1681

Answers (4)

akhilesh gulati
akhilesh gulati

Reputation: 128

public void longClick(String element) {
        // TODO Auto-generated method stub
        WebElement webElement = appiumDriver.findElement(By.xpath(element));

        TouchAction Action = new TouchAction(appiumDriver);
        Action.longPress(webElement).release().perform();
    }

Upvotes: 0

Nick Latkovich
Nick Latkovich

Reputation: 125

CHANGES IN VERSION 1.5

Remove long-deprecated mobile: xxx

So you should:

  • Install Android Support Repository...

    The Android Testing Support library is available through the Android SDK Manager

    To download the Android Support Repository through the SDK Manager:

    1. Start the Android SDK Manager.
    2. In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.
    3. Select the Android Support Repository item.
    4. Click the Install packages... button.
  • Use TouchAction

    driver.performTouchAction(new TouchAction(driver).tap(x, y));

Upvotes: 2

Amaan Memon
Amaan Memon

Reputation: 154

    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, String> longTapObject = new HashMap<String, String>();
    longTapObject.put("element",((RemoteWebElement)w1).getId());
    js.executeScript("mobile: longClick", longTapObject);

The above code is working for me in java Appium version 1.2.4.1

Upvotes: 1

jain28
jain28

Reputation: 137

mobile:longClick  is no longer supported by appium version greater than 1.0.0. As you are using Appium version 1.2.0. so you have to perform this action by using something like this.

Eg:

 testObject = this.WaitAndGetElement();//element on which long tap is to be performed          
TouchAction action = new TouchAction(rm);// rm is the instance of appium driver.       
Thread.Sleep(1000); 
action.Press(testObject).Wait(1000).Perform();

For more information you can visit: TouchAction

Please let me know if it helps

Upvotes: 1

Related Questions