Click back button on android device in Java

I can’t seem to find the code that works yet. Anyone, can you share Click back button on android device in Java code that works?

Thanks in advance.

driver.pressKeyCode(AndroidKeyCode.BACK);

5 Likes

It worked perfect! Thank you!

For future reference, I look at the source code on github

After that, I ust searched through the repo for “back”

3 Likes

working thanks…

driver.navigate().back();

2 Likes

While the keycode was deprecated. this worked for me. Thanks

Use
driver.pressKey(new KeyEvent(AndroidKey.BACK));

Imports
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;

6 Likes

Yes. this worked perfectly for me. the earlier one showed as a deprecated one.
Thanks for the help.

Its not working for me .
i m getting this error
The method presskeycode(int)is undefined for the type AppiumDriver<capture#19-of?>

Thank you, It works for me

is there any other way(W3C) apart from driver.navigate().back(); after upgrading to appium java client version 8.2.0 to tap on Android back button using AppiumDriver

You could try something similar to https://github.com/appium/java-client/blob/f185039f9f75e86e041320324e314b9f1b655d71/src/test/java/io/appium/java_client/android/KeyCodeTest.java#L41