I am using the following environment:
PL: Java
Appium java client 7.0.0
Appium server version: 1.13.0
Device Samsung Galaxy S8
Android Version 9.0
but when try to enter the following code to click the Android Home key:
driver.pressKeyCode(AndroidKeyCode.HOME);
But I get the compiler message that it is deprecated. How can I click the Home key?
Thanks for any Support
You can use pressKey() instead of pressKeyCode.
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;
//initialize AppiumDriver
((AndroidDriver<MobileElement>) driver).pressKey(new KeyEvent(AndroidKey.HOME));
The alternative way to click home button is:
String cmd = "adb shell input keyevent 3";
Runtime.getRuntime().exec(cmd);