gaurav jain
gaurav jain

Reputation: 3234

Status Bar Height in android using Selenium

I've been working on Appium testing, and writing Java code for automation testing. For a problem, I need to identify the height of the status bar for Android device/emulator. The web driver getSize() method includes the complete screen, and hence the height of the status bar as well. Is there a way to solely identify the height of the status bar?

What I've tried is finding the status bar by id : com.android.systemui:id/status_bar, but the findElementById() throws an exception : "An element could not be found on page using given search parameters." I think, it only locates ids within the application screen area, hence it doesn't find status bar id. Any help/tips would be appreciated.

Upvotes: 1

Views: 1254

Answers (2)

Pepe
Pepe

Reputation: 24

As I just stumbled across this one when searching a related topic, I decided to create my very first comment here, even this is a very old post...

As of today the AndroidDriver returns the status bar height in its capabilities. In C# you get that information from:

AndroidDriver<AppiumWebElement> driver = new AndroidDriver<AppiumWebElement>(appiumHubUrl, desiredCapabilities);
object statBarHeightObj = driver.Capabilities.GetCapability("statBarHeight");
// go on with conversion....

The capabilites even show information about the ViewPort Rectangle and the Pixel Ratio, which might come in handy when dealing with hybrid apps.

Upvotes: 0

STK
STK

Reputation: 86

You can check the appium inspector or uiautomationviewer to get the screen shot of the screen. From that you will be able to find the status bar item and its locator properties. It include the hieght width of the status bar. Also you can find the same from your automation code once you find the status bar element.

Upvotes: 0

Related Questions