How click on options from floating action button

Hi,

I’m automating an app that has an floating action button with some options like follow image. The main button (that opens the options) is possible to click, but I can’t click on the options, because there isn’t specification for this elements on the UI Automator viewer. Can you help me please? How can I automating the click on this buttons?

The floating action button has animation and has attributes defined in xml archive, but these attributes aren’t showed in UI Automator viewer.

Hey,

It worked for me I used the same with its respective index,

driver.findElement(By.xpath("//android.widget.ImageButton[@index=‘2’]")).click();

Regards,
Rahul

Hi @Rahul_Khanduri

It don’t work for me, because the attributes from the options “Create Channel”, “Create Photo” etc., aren’t showed in UI Automator. I saw the xml archive on AndroidStudio and these buttons have attributes, like class name, id, etc., but if I try use one of these attributes, the appium show me the message that element couldn’t be found, because the attributes aren’t showed in UI Automator.

If you are absolutely sure that they are not visible in UIAutomatorviewer, you will have to tap on them “blindly”. You can use percentage p.e.:

public static void tapPercentage(AppiumDriver driver, double x_percentage, double y_percentage) throws Exception {
    Dimension size = driver.manage().window().getSize();

    int xPoint = (int) (size.width * x_percentage);
    int yPoint = (int) (size.height * y_percentage);
    TouchAction touchAction = new TouchAction(driver);
    touchAction.tap(xPoint, yPoint).perform();
}

Or you can use direct coordinates, but for that you should gather device density in order to calculate what are the proper coordinate to tap.

Ok. I wouldn’t want to use tap for location, but if I don’t have other solution it’s a good idea. So, how I can calculate the x and y percentage?

Well, if they dont appear anywhere you will have to do trial an error. Place the app in debug mode and keep sending commands from your IDE.

You should also confirm that in driver.getPageSource() those buttons are not there. Also if you use percentage, it may differ from device to device depending on the way it is implemented.

Boa sorte! :slight_smile:

I got it! Thank you! I did the method of trial an error for find the exact percentage =)

Obrigada!:slight_smile: