Appium Concepts — π§ͺ How to Use Appium’s .getSystemBars() Method to Detect ‘Status & Navigation’ Bars information
Watch the video below for your complete step-by-step guide!
In this Article, We will discuss about ‘How to Use Appium’s .getSystemBars() built-in method to Detect ‘Status & Navigation’ Bars information.
π― What You’ll Learn in This Article:
- ✅ What are Android System Bars? (Status Bar & Navigation Bar)
- π How to use Appium’s
.getSystemBars()method - π‘ Why it matters: Key use cases in mobile UI automation
- ⚙️ How to configure the emulator to display the navigation bar
- π« Limitations and edge cases of
.getSystemBars() - π Understanding the “Usable Screen Area” in mobile devices
- π» Full working Java example with step-by-step explanation
driver.getSystemBars()— Complete Guide
Purpose:
The getSystemBars() method is used to fetch properties of Android system UI components: the status bar (top) and navigation bar (bottom/back/home buttons).

This helps determine:
- Whether these bars are visible
- Their height in pixels
This information is crucial in visual validation, coordinate calculations, and pixel-perfect UI automation.

Method Signature (Java):
Map <String, Map <String, Object>> getSystemBars()
Map<String, Map<String, Object>> is a nested Java Map structure. Here's a breakdown of what it means and how to use it effectively.
What is Map<String, Map<String, Object>>?
Outer Map: Keys are String
Value of each key in outer map: Another Map with:
Keys: String
Values: Object (can be any data type)Returned Data Structure
The method returns a Map<String, Object> with two main keys:
{
"statusBar": {
"visible": true,
"height": 72
},
"navigationBar": {
"visible": true,
"height": 144
}
}1. Status Bar
visible:trueorfalse(Boolean)height: Height of the status bar in device pixels
2. Navigation Bar
visible:trueorfalse(Boolean)height: Height of the navigation bar in device pixels
Java Code Example:
//To get Android System bars information - Status Bar & Navigation Bar
System.out.println("To get Android System bars information - Status Bar & Navigation Bar");
Map <String, Map <String, Object>> systemBars=driver.getSystemBars();
System.out.println("Navigation Bar & Status Bar: " +systemBars);
Map<String,Object> StatusBar=(Map<String,Object>)systemBars.get("statusBar");
Map<String,Object> NavBar=(Map<String,Object>)systemBars.get("navigationBar");To enable the Navigation Bar in an Android emulator,
you can follow these methods depending on the Android version and emulator configuration:
✅ Method 1: Use Emulator Settings (For Gesture-Free Navigation)
- Launch Emulator
- Go to Settings > System > Gestures > System Navigation
- Select “3-button navigation” to enable the traditional navigation bar (Back, Home, Overview buttons)
✅ Method 2: Use ADB Command
Run the following ADB command to enable the navigation bar:
adb shell settings put secure sysui_nav_bar "space,recent;home;back"To apply it on a running emulator:
adb -s emulator-5554 shell settings put secure sysui_nav_bar "space,recent;home;back"Then reboot:
adb rebootUse Cases:(Important):

⚠️ Limitations / Considerations
- Android only
- Returns values in physical pixels, not dp/sp (density-independent units)
- Might return inaccurate results on:
- Devices with gesture-based navigation (no visible navbar)
- Immersive apps where bars auto-hide
- Might require slight delay after activity load for reliable results
π Best Practices
- Always cast returned values properly (
Map<String, Object>) - Use in combination with screen size to calculate usable space:
Dimension screenSize = driver.manage().window().getSize();
int usableHeight = screenSize.getHeight() - (statusBarHeight + navBarHeight);- Consider calling after a wait for proper visibility state.
“Complete Code: Optimized and Ready to Use”:
package com.appiumguide.appiumconcepts;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.io.IOException;
import java.net.*;
import java.time.Duration;
import java.util.Map;
/**
* Script Details - Appium Concepts : π§ͺ How to Use Appium’s .getSystemBars() Method to Detect “Status & Navigation Bars”
*
* appium-java-client version: latest
*
* @author 'Ramesh Kodumuru' for AppiumGuide [appiumguide@gmail.com]
*/
public class GetSystemBarsDemo {
private AndroidDriver driver;
@BeforeTest
public void setup() throws MalformedURLException {
UiAutomator2Options cap=new UiAutomator2Options();
cap.setPlatformName("android");
cap.setAutomationName("uiautomator2");
cap.setDeviceName("Pixel6");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), cap);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(100));
}
@Test
public void test() throws InterruptedException, IOException {
//To get Android System bars information - Status Bar & Navigation Bar
System.out.println("To get Android System bars information - Status Bar & Navigation Bar");
Map <String, Map <String, Object>> systemBars=driver.getSystemBars();
System.out.println("Navigation Bar & Status Bar: " +systemBars);
Map<String,Object> StatusBar=(Map<String,Object>)systemBars.get("statusBar");
Map<String,Object> NavBar=(Map<String,Object>)systemBars.get("navigationBar");
//To Print Visibility & Height of Status Bar
System.out.println("To Print Visibility & Height of Status Bar");
System.out.println("Status Bar - Visible or not - "+StatusBar.get("visible"));
System.out.println("Status bar - Height - "+StatusBar.get("height"));
//To Print Visibility & Height of Navigation Bar
System.out.println("To Print Visibility & Height of Navigation Bar");
System.out.println("Navigation Bar - Visible or not - "+NavBar.get("visible"));
System.out.println("Navigation bar - Height - "+NavBar.get("height"));
}
@AfterTest
public void teardown() {
if(driver!=null) {
driver.quit();
System.out.println("Test Completed");
}
}
}Result(screenshot);

GitHub Link:
π¬ Explore More! Watch My Latest Videos on YouTube!

No comments:
Post a Comment