mahendra seervi
mahendra seervi

Reputation: 25

Exception in thread "main" java.lang.NoSuchMethodError: io.appium.java_client.TouchAction.longPress(Lorg/openqa/selenium/WebElement;)

My Appium Java code:

package Generic;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.remote.MobileCapabilityType;

import io.appium.java_client.MobileDriver;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

public class AppiumSelenium {

    //AndroidDriver Ad=new AndroidDriver();
    public static void main(String arg[]) throws MalformedURLException, InterruptedException {

DesiredCapabilities dc= new DesiredCapabilities();

        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");

        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");

        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");

        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");

        dc.setCapability(MobileCapabilityType.APP, "/home/connexis/appium/AppiumMobile/src/main/java/Apps/ApiDemos.apk");

        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver<WebElement> driver= new AndroidDriver<WebElement>(url,dc);

        driver.findElementsById("android:id/text1").get(1).click();

        WebElement info=driver.findElementsById("android:id/text1").get(1);


        int x1=info.getLocation().getX();
        int y1=info.getLocation().getY();

        //we need end coornidates a.longPress(x).moveTo(startX, endY).release().perform();too hence , lets use some formulat to geterate


        int x2=x1 /2;
        int y2=y1 /2;






        TouchAction a = new TouchAction((MobileDriver) driver);
        -------------------------------------------------------

        a.longPress(info).moveTo(x1, y2).perform().release();






        /*
        List<WebElement> val=driver.findElementsById("android:id/text1");
        //it should retrive all the objects means 30 or 40 whatever present in that app

        for(int i=0;i<val.size();i++){

            System.out.println(val.get(i).getText());

        }
        */

        Thread.sleep(9000);

        driver.quit();

    }

}

Environment Set :

 Selenium server standalone 2.53
>     java-client 5.0.4
>     java-client 6.1.0

Error logs

Oct 04, 2018 3:07:53 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0 INFO: Detected dialect: W3C Exception in thread "main" java.lang.NoSuchMethodError: io.appium.java_client.TouchAction.longPress(Lorg/openqa/selenium/WebElement;)Lio/appium/java_client/TouchAction; at Generic.AppiumSelenium.main(AppiumSelenium.java:52)

Upvotes: 1

Views: 831

Answers (2)

Suban Dhyako
Suban Dhyako

Reputation: 2526

In your code you cannot pass webelement in longpress(). LongPress() takes point option as its parameter. Modify your code as following:

   new TouchAction(driver).longPress(PointOption.point(x1, y1)).moveTo(PointOption.point(x2, y2)).perform().release();

If you want to vertical scroll you can use do it as follow:

 public static void swipe(int startX, int endX, int startY, int endY) {
        try {
            new TouchAction(Init.driver).press(PointOption.point(startX, startY)).waitAction(WaitOptions.waitOptions(ofSeconds(1)))
                    .moveTo(PointOption.point(endX, endY)).release().perform();              
        } catch (Exception e) {
            System.out.println("unable to swipe");
        }
    }

Upvotes: 0

Amit Jain
Amit Jain

Reputation: 4587

If you look at release version https://github.com/appium/java-client/releases/tag/v6.0.0-BETA1 the usage of TouchActions are changed and they accept io.appium.java_client.touch.ActionOptions and sublasses were added

Please refer the unit tests of Appium for TouchActions class here

Upvotes: 2

Related Questions