How to longPress in Appium 1.7?

down vote
favorite
I am new to appium and using its version 1.7

i have to long press a webelement in my native app on android version 7.0 It shows all the methods are depreciated except for longPress(LongPressOptions longpressoptions) and longPress(PointOption longpressoptions). so i started using it like below

I am using it like below

public static RemoteWebDriver driver;
driver = new RemoteWebDriver(new URL(“http://0.0.0.0:4723/wd/hub”), capabilities);
WebElement homeScrSwipe = driver.findElementById(“pulldown_image”);
TouchAction ta = new TouchAction((PerformsTouchActions) driver);
ta.longPress(homeScrSwipe, Duration.ofMillis(5000)).release().perform();
but it always gives me below error

The method longPress(WebElement, Duration) from the type TouchAction is deprecated.

If someone could let me know what is this longPressOptions in both the methods and what arguments to provide that would be of great help

Any Suggestion ? Please advice

I would like to help you, but I also struggle with it, and I couldn’t find some good examples. So waiting for an answer too.

if its deprecated, its not an error, just a warning.

I still didn’t updated my methods also, but you can check here what methods you should use instead:

https://appium.github.io/java-client/io/appium/java_client/TouchAction.html

@Telmo_Cardoso Yes you are right. but i want to know how to use longPressOptions and tapOptions

@Telmo_Cardoso, @Nemanja_Maksic, @mohak.barokar
I tried it like below but that did not perform any action. Any Advice for below code ?
Dimension sz = driver.manage().window().getSize();
int xloc = sz.getWidth() / 2;
int yloc = sz.getHeight() / 2;
TouchAction ta = new TouchAction((PerformsTouchActions) driver);
ta = ta.tap(TapOptions.tapOptions().withPosition(PointOption.point(xloc, yloc)));
ta.release().perform();

1 Like