1

Screenshot:

I am trying to use the element ID in appium to automate click menu button. It is not set by default and it shows NULL without element ID or Text it is not possible. Could anyone help me in this?

croxy
  • 4,082
  • 9
  • 28
  • 46
Dennis S
  • 11
  • 2

3 Answers3

2

You can use this:

driver.findElementByName("Open navigation drawer").click();

OR

driver.findElementByXPath("//*[@class='android.widget.ImageButton' and @content-desc='Open navigation drawer']").click();
Gaurav
  • 1,332
  • 11
  • 22
  • Please keep in mind that using content description value is a bit risky. When device language changes then content description is being change accordingly to chosen language. – Slavo Jan 14 '16 at 14:53
  • @Slavo i never had this problem. Plus i have also given second option. Thanks – Gaurav Jan 14 '16 at 15:08
1

You can always find element by XPath, it could be done by:

  1. Using annotations to declare elements (remember to import @FindBy):

@FindBy(xpath = "//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.TextView[1]") private WebElement elementName;

  1. Using findElement inside the code: driver.findElementByXPath("putXpathHere");

XPath of an element can be found in Appium's inspector below the ID.

If you want to use IDs instead of xpath in this case, I'm afraid you will have to add resource id's inside the application code.

Slavo
  • 494
  • 4
  • 15
0

You can click Hamburger icon using it content description. Like this:

    driver.findElementByAccessibilityId("Open navigation drawer").click();
Sajid Zeb
  • 1,806
  • 18
  • 32