How to handle touch event listener on Hybrid App

We are testing an iOS Hybrid App. Within it’s Web View there are html

elements registered with javascript touch event listener. But I don’t get the clue why I can’t simulate a simple tap (touchstart - touchend) with appium IOSDriver.

Tested with
Appium 1.53, IOS Simulator iPad Air 9.2
Appium 1.62, IOS Simulator iPad Air 10 (I used still the iOS Driver maybe its a problem?)

I tried the following appium functions:
ele = (List)driver.findElementsByXPath("//div[@id=’"+id+"’]").get(0);
ele.click();
ele.tap(1,100);

TouchAction action = new TouchAction(driver);
action.press(ele).perform();

Can anyone help?

I’m using Ruby for my tests, but if you have the correct element and you are using the press action, you need to release the press. Also you usually need to pass in the elements x/y coordinates.

In Ruby it would be something like

element = driver.find_element(locator)
x_position = element.location_rel.x
y_position = element.location_rel.y

Appium::TouchAction.new.press(x: x_position, y: y_position).release.perform

For Java checkout this link:
http://appium.github.io/java-client/io/appium/java_client/TouchAction.html#press(int, int)

Many thanks for your help. It seems to work if i get the center of the element where i want to touch on and using the tap function of the TouchAction class.

Java snippet
int x = element.getCenter().x;
int y = element.getCenter().y;
driver.performTouchAction(new TouchAction(driver).tap(x, y));

But anyway it feels more like a workaround then a clean implementation.