Reputation: 392
`
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/nav_gradient"
android:fitsSystemWindows="true"
android:paddingEnd="10dp"
android:paddingStart="20dp"
android:paddingTop="30dp"
android:theme="@style/AppTheme.NavigationTheme"
app:itemBackground="@android:color/transparent"
app:itemIconTint="@color/drawer_item"
app:itemTextColor="@color/drawer_item"
app:menu="@menu/activity_home_drawer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:orientation="horizontal"
android:paddingBottom="20dp">
<ImageView
android:id="@+id/iv_toolbar_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:scaleType="fitCenter"
android:src="@drawable/logoimg" />
<TextView
android:id="@+id/tv_toolbar_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginStart="10dp"
android:maxLines="1"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.design.widget.NavigationView>
`I am trying to test android app which contains hamburger menu using Appium. I tried with find by Xpath, id, accessibilityId & className. All are not working.
This is how I am initialising driver.
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capability);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElementByAccessibilityId("Open navigation drawer").click();
driver.findElementById("Open navigation drawer").click();
driver.findElementByXPath("//android.widget.ImageButton[@content-desc='Open navigation drawer']").click();
driver.findElementByClassName("android.widget.ImageButton").click();
Please help me on this. Thanks in advance.
Upvotes: 0
Views: 1642
Reputation: 1830
If you could post the source code for the element you're trying to find and click on, it'd be helpful. However, I can make some guesses.
driver.findElementByClassName("android.widget.ImageButton");
Did you forget .click()
here?
driver.findElementByAccessibilityId("Open navigation drawer").click();
driver.findElementById("Open navigation drawer").click();
Are you sure Open navigation drawer
is the ID of this element. It seems be the value of the content-desc
attribute according to driver.findElementByXPath("//android.widget.ImageButton[@content-desc='Open navigation drawer']").click();
According to http://appium.io/docs/en/commands/element/find-elements/, you should avoid XPath selection due to performance issues.
Double check that you've got the correct ID
and Accessibility ID
; and you're not making the mistake as described above.
Upvotes: 1