Get screen and browser size

I’m using Appium in Ruby on Android real device Galaxy S4
I’m looking to get the screen and browser size but right now I’m using, after opening my webpage on Chrome:

@browser.execute_script(“return window.innerWidth”).to_i
@browser.execute_script(“return window.innerHeight”).to_i
@browser.execute_script(“return window.outerWidth”).to_i
@browser.execute_script(“return window.outerHeight”).to_i
@browser.execute_script(“return screen.width”).to_i
@browser.execute_script(“return screen.height”).to_i

But I have some very weird results (quite the same thing with Genymotion), because the S4 resolution is 1080 x 1920:

Windows innerwidth 980 - Windows outerwidth 360 - Screen width 360
Windows innerheight 1522 - Windows outerheight 559 - Screen height 640

So because it looks like java script is not recommanded with Watir, have you another way than js to get sizes ?

my capabilities:
capabilities = {
caps: {
‘browserName’ => ‘Chrome’,
‘platformName’ => ‘Android’,
‘deviceName’ => ‘Android’
appium_lib: {
sauce_username: nil, # don’t run on Sauce
sauce_access_key: nil
@driver_appium =
@driver = @driver_appium.start_driver
@browser = @driver
@browser.driver.manage.timeouts.implicit_wait = 15

Hi Eric,

Did you manage to get it? I’m facing the same issue

I’ve also found that window.screen.height is returned not correct result.
Samsung Tab 3 - correct, Samsung Note 2 - not correct
However, window.innerHeight seems return correctly for both.

I will try to link on that. Do you have better ideas or findings?

Hello Max,
What I did is just multiply the value I get by 3 and It gives me the exact pixel size screen of my Samsung Galaxy S4…
I didn’t search further…

Because they return values in CSS pixels. Plesae find this link.

Screen size:


1 Like