10

I am working on test automation for a hybrid mobile application on Android using Appium(python client library). I haven't been able to figure out any means to automate or create a gesture for using the Phone back button to go back to the previous page of the app. Is there any driver function that can be used? I tried my luck with self.driver.navigate().back() [hoping this would simulate the same behaviour as in Selenium to navigate to the previous URL] but to no avail. Can anyone suggest a way out?

Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
Monica
  • 101
  • 1
  • 1
  • 4

10 Answers10

14

Yes,try the driver.back(), it simulates the system back function.

Matt Seymour
  • 8,880
  • 7
  • 60
  • 101
Ying Ma
  • 191
  • 1
  • 11
13

I guess maybe it depends on what version of the client library are you using because in Java driver.navigate().back() works well.

6

Recently I was automating one of the Native application where I had to click on back button.

I tried below code and it worked for me.

Code for Android back button.

driver.pressKeyCode(AndroidKeyCode.BACK);

This will click on back button

Mukesh otwani
  • 821
  • 8
  • 11
2

I used a KeyEvent.

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.nativekey.AndroidKey;

driver.pressKey(new KeyEvent().withKey(AndroidKey.BACK));
kklw
  • 858
  • 3
  • 13
  • 28
1

For appium-python-client, to go back you should call this method:

driver.press_keycode(4)

Sajid Manzoor
  • 487
  • 1
  • 5
  • 9
0

driver.sendKeyEvent(AndroidKeyCode.BACK);

does the job in Java

Santosh Pillai
  • 8,169
  • 1
  • 31
  • 27
0

It may be late but useful To click android device back button following line will help you.

helper.driver.pressKeyCode(AndroidKeyCode.BACK);

To click android recent apps button following line will help you.

helper.driver.pressKeyCode(187);
Hamed Baziyad
  • 1,954
  • 5
  • 27
  • 40
0

By using back(),

self.driver.back()
RAHUL GUPTA
  • 91
  • 1
  • 3
0

you use this code for python.

driver.press_keycode(AndroidKeyCode.BACK)
Roll no1
  • 1,315
  • 1
  • 16
  • 23
farzane
  • 1
  • 1
-1

Use this one it works 100%

driver.pressKeyCode(4);

as "4" is the key note for Back press on Android

matsjoyce
  • 5,744
  • 6
  • 31
  • 38