Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate the android phone back button using appium

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?

like image 318
Monica Avatar asked Jun 12 '15 11:06

Monica


3 Answers

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

like image 134
Ying Ma Avatar answered Oct 12 '22 23:10

Ying Ma


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

like image 31
Kristaps Mežavilks Avatar answered Oct 12 '22 23:10

Kristaps Mežavilks


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

like image 23
Mukesh otwani Avatar answered Oct 12 '22 23:10

Mukesh otwani