Not able to click on bottom Menu using Appium

Hello Sir/mam,

I am trying to click on the bottom menu using Appium, but I have no proper idea that how to click on bottom menu using Appium using java code for android device. Would you please help me out OR please send me some code.

If the bottom menu items does not have accessibility ID, try asking your dev team to add accessibility IDs or try writing an unique xpath for those elements like driver.findElement(MobileBy.AndroidUIAutomator( String.format("new UiSelector().description(\"%s\")", "Home"))).click();
driver.findElement(MobileBy.AndroidUIAutomator( String.format("new UiSelector().description(\"%s\")", "My Ads"))).click();

Can I use resource-id , class name ?

Hey @massi_mass, I suggest not to go with the class approach, using id or resource-id is better and reliable. Many times developer may change the class names or class hierarchy.

Screenshot%20(25)

Hello

above code is not working in Appium, here the 2 screenshots please help me out with code.

Please help me out I am stuck in very bad situation.

These buttons are not accessible via UiAutomator. You must use pressKey with appropriate key codes (for example HOME) to simulate taps on these buttons.

Hello sir,

Do you have any example code, then please share with me so I can get more idea on this.

@Massi_mass Have you tried clicking using the given text

yes I try with this code

1). driver.findElementByAndroidUIAutomator(“text(“Account”)”).click();

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

@Massi_mass try:

        WebElement el = driver.findElement(MobileBy.id("navigation_acc????")); // can not see full ID on your second screenshot
        TapOptions tapOptions = new TapOptions().withElement(ElementOption.element(el));
        new TouchAction(driver).tap(tapOptions).perform();
1 Like

Hello Sir,

I use the code but steps are not going forward.

WebElement el = driver.findElement(MobileBy.id(“com.souqbh:id/navigation_account”));
TapOptions tapOptions = new TapOptions().withElement(ElementOption.element(el));
new TouchAction(driver).tap(tapOptions).perform();

@Massi_mass lets add some debug output:

        List<WebElement> elements = driver.findElements(MobileBy.id("navigation_account")); // package name NOT needed
        System.out.println("elements size: " + elements.size());
        try {
            Thread.sleep(10000); // 10 sec sleep and try again to see something
        } catch (Exception e) {
            // ignore
        }
        elements = driver.findElements(MobileBy.id("navigation_account")); // package name NOT needed
        System.out.println("elements size: " + elements.size());
        if (!elements.isEmpty()) {
            MobileElement el = (MobileElement) elements.get(0);
            System.out.println("element x: " + el.getCenter().x + ", y: " + el.getCenter().y);
            TapOptions tapOptions = new TapOptions().withElement(ElementOption.element(el));
            new TouchAction(driver).tap(tapOptions).perform();
        }

Hello Sir,

after running my application with the same code of your, I’ll wait for the response, so I attached one screenshot please checked.

@Massi_mass check your code. see problem in findElementByXpath! while in mine code no such text.

Hello Sir,

Check this is my full code.

package Emulator;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.touch.TapOptions;
import io.appium.java_client.touch.offset.ElementOption;

public class Continue_Guest {

@Test
public void testScrolling() throws MalformedURLException , InterruptedException {
	
	DesiredCapabilities cap = new DesiredCapabilities();
	cap.setCapability(MobileCapabilityType.DEVICE_NAME, "demo");
	cap.setCapability(MobileCapabilityType.APP, System.getProperty("user.dir")+"//src//application//SouqBH_v1_1.3_22-08-19-debug.apk");
	AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
	driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
	
	driver.findElementByAndroidUIAutomator("text(\"Continue\")").click();

	driver.findElementByAndroidUIAutomator("text(\"Skip\")").click();
	
	driver.findElementByAndroidUIAutomator("text(\"Continue as a guest\")").click();
	

	driver.findElementByXPath("//*[@text='Account']").click();
	
	List<AndroidElement> elements = driver.findElements(MobileBy.id("com.souqbh:id/ivToolbarRight")); 
    System.out.println("elements size: " + elements.size());
    if (!elements.isEmpty()) {
        MobileElement el = (MobileElement) elements.get(0);
        System.out.println("element x: " + el.getCenter().x + ", y: " + el.getCenter().y);
        TapOptions tapOptions = new TapOptions().withElement(ElementOption.element(el));
        new TouchAction(driver).tap(tapOptions).perform();
    }
}

}

Remove line that cause problem -> findElementByXPath. Or comment it for a while.

Hello Sir,

Now It show element size = 0. It does not tap on the account button.

  1. set as i wrote pls. Without package name
    MobileBy.id(“navigation_account”)
  2. add in end of test:
    System.out.println(driver.getPageSource());

Share result as TXT file or link in gist.github.com

Pls do not write this long text here.

Hello Sir,

as you told so I add code System.out.println(driver.getPageSource()); , and founded result I attached in txt file please check.file.txt (2.0 KB)