Search code examples
appium

Appium: Unable to perform click on a "+" button


I am trying to automate a mobile app, and I am having issues in trying to click a "+" to add new line of data.

From getsource(), the code for the element is

                <android.widget.ImageButton index="0" package="mobi.littlebytes.android.bloodglucosetracker" class="android.widget.ImageButton" text="" resource-id="mobi.littlebytes.android.bloodglucosetracker:id/fab" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[844,1558][1038,1752]" displayed="true" />
              </android.widget.RelativeLayout>

and my failed code is

a.moveToElement(driver_App.findElement(By.xpath("//[@id='fab']"))).click().build().perform();

I have also tried

a.moveToElement(driver_App.findElement(By.xpath("//*[@id='mobi.littlebytes.android.bloodglucosetracker:id/fab']"))).click().build().perform();

but failed as well, that is, couldn't get to click the "+" button. Hope to have advice.

I attached the image of the button

enter image description here


Solution

  • Try clicking the element by using the xpath:

    driver_App.findElement(By.xpath("//*[@resource-id='mobi.littlebytes.android.bloodglucosetracker:id/fab']")).click();