Currently I am loading an image in a webview. I want to be able to tap the image, but when I do so it doesn't seem to actually register in Sauce Lab.
IOSDriver driver = (IOSDriver) contextObj.getValue("driver");
final JSONObject params = new JSONObject(parameters);
Set<String> contextHandles = driver.getContextHandles();
ArrayList<String> contexts = new ArrayList<String>();
for (String context : contextHandles) {
contexts.add(context);
System.out.println("Available Context: " + context);
}
String newContext = contexts.get(1);
driver.context(newContext);
seleniumSteps.driverWait("15000");
System.out.println(driver.getPageSource());
WebElement firstDivElement = driver.findElement(By.xpath("(//div)[1]"));
Point imageLocation = firstDivElement.getLocation();
Dimension size = firstDivElement.getSize();
int elementCenterX = imageLocation.getX() + Math.round(size.getWidth() / 2);
int elementCenterY = imageLocation.getY() + Math.round(size.getHeight() / 2);
System.out.println("X Coordinate: " + elementCenterX);
System.out.println("Y Coordinate: " + elementCenterY);
driver.context("NATIVE_APP");
seleniumSteps.driverWait("5000");
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence tap = new Sequence(finger, 1);
tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), elementCenterX, elementCenterY));
tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Arrays.asList(tap));
I've tried to use the deprecated touchActions class and get the same result.
After much digging I found that you need to enable a capability on startup to allow taps to happen.
Here is what worked for me:
caps.setCapability("nativeWebTap",true);