Hi all,
Using:
io.appium java client 6.1.0
selenium-java 3.14.0
guava 26.0-jre
UIAutomator2
on Oreo and Marshmallow.
I have tried to do some workaround for the same.
//Get X Y Coordinates
public Map<String, ArrayList> Get_XY(MobileElement element, String elementName) throws InterruptedException{
p = new Point(0, 0);
try{
p = element.getLocation();
x = 80 + p.getX();
hmItemsCoord.put(elementName, new ArrayList<Integer>()); //new LinkedList<String>()
hmItemsCoord.get(elementName).add(x);
hmItemsCoord.get(elementName).add(p.getY());
elementGap = p.getY()-y;
hmItemsCoord.get(elementName).add(elementGap);
y = p.getY();
LOGGER.info("TRY_hmItemsCoord.toString(): "+hmItemsCoord.toString());
LOGGER.info("Element: "+elementName+" coordinates: ["+x+", "+y+"]. ");
}catch(NoSuchElementException nsee){
hmItemsCoord.put(elementName, new ArrayList<Integer>()); //new LinkedList<String>()
hmItemsCoord.get(elementName).add(x);
hmItemsCoord.get(elementName).add(y+elementGap);
hmItemsCoord.get(elementName).add(elementGap);
LOGGER.info("NSEE_hmItemsCoord.toString(): "+hmItemsCoord.toString());
temp = y + elementGap;
a[1] = temp;
y = temp;
LOGGER.info("Element: "+elementName+" not found in XML DOM. Getting approximate coordinates: ["+x+", "+y+"]. ");
}finally{
LOGGER.info("Control is in 'Finally' Block. ");
}
return hmItemsCoord;
}
You can use this method to get all the required coordinates of the HM links along with the elementGap.
Next, you need to use the below method to tap on the relevant HM links:
//Tap on X Y Coordinates
public Map<String, ArrayList> Tap_XY(MobileElement element, String elementName) throws InterruptedException{
x = hmItemsCoord.get(elementName).get(0)+rnd.nextInt(5);
y = hmItemsCoord.get(elementName).get(1)+rnd.nextInt(50);
new TouchAction(driver).tap(PointOption.point(x, y)).perform();
LOGGER.info("Clicked on ["+x+", "+y+"]. ");
TimeUnit.SECONDS.sleep(2);
return hmItemsCoord;
}