Shrikanth Kalluraya
Shrikanth Kalluraya

Reputation: 1119

Press Home button in Appium Java client

I am new to appium. It might be a silly question. Wanted to know how will i click home button using java bindings.

Thanks in advance

Upvotes: 4

Views: 9701

Answers (7)

jagdish gaikwad
jagdish gaikwad

Reputation: 1

I am using java client 8.5.0 and below code works fine for me

    driver.pressKey(new io.appium.java_client.android.nativekey.KeyEvent(AndroidKey.HOME));

Upvotes: 0

Ravenz16
Ravenz16

Reputation: 1

closeApp() for me - its force stop of app. If u dont need it u can use:

driver.runAppInBackground(Duration.ofSeconds(x));

puts the application in the background for a certain time. Unfortunately this is the only solution that helped me with MIUI.

Upvotes: 0

Hacci56
Hacci56

Reputation: 39

For Android :

driver.pressKeyCode(AndroidKeyCode.HOME);

For IOS:

driver.executeScript("mobile: pressButton", ImmutableMap.of("name", "home"));

Upvotes: 0

loroz
loroz

Reputation: 191

Appium has since deprecated pressKeyCode. Instead, use:

driver.pressKey(new KeyEvent(AndroidKey.HOME));

Upvotes: 6

Jitesh Mohite
Jitesh Mohite

Reputation: 34210

please try below code

driver.pressKeyCode(AndroidKeyCode.HOME);` // it will android device home` button 

if you want to perform any other operation with android device keys you can use same approach.You will get keys in AndroidKeyCode.

hope these helps you.

Upvotes: 0

akhilesh gulati
akhilesh gulati

Reputation: 128

public boolean applicationClose(String packageName) {
        appiumDriver.closeApp();
        return true;
    }

or
String ud_id=  ;
String str = "adb -s ud_id shell keyevent KEYCODE_HOME";
        String line;
        try {
            Process p = Runtime.getRuntime().exec(commandStr);
            InputStream is = p.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);

            while ((line = br.readLine()) != null)
                str += line;

            System.out.println("Command output: " + str);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        ReportAppium.getSnapShot(appiumDriver, "run:" + commandStr);
        return str;

Upvotes: 0

Chandrashekhar Swami
Chandrashekhar Swami

Reputation: 1780

Well if you want to send an app in background then simply use driver.CloseApp() function and relaunch it by driver.OpenApp()

You can also use press keycode method Below are the codes

Home Menu Button - 82
Back Button - 4
Recent app - 187

Upvotes: 6

Related Questions