Search code examples
androidpythonappiumappium-android

self.driver.get_window_size() not returning dictionary with height or width


I'm having a problem on getting the size of the device with my Appium script. My plan is to make a function like the one below to get the screen size and then calculate the points which are used in the swipe operation.

size = self.driver.get_window_size()
start_y = size.height * 0.5
end_y = size.height * 0.5
start_x = size.width * 0.8
end_x = size.width * 0.2
self.driver.swipe(start_x, start_y, end_x, end_y, 400)

The problem I have with this code is that apparently it's not returning a dictionary with the height and width attributes. Error:

  File "/path/tests/AppiumTest.py", line 88, in swipe_right_to_left
start_x = size.width * 0.8
AttributeError: 'dict' object has no attribute 'width'

Any ideas on what I am doing wrong?


Solution

  • Found my fault. This would be the correct way on doing it:

    start_y = size['height'] * 0.5
    end_y = size['height'] * 0.5
    start_x = size['width'] * 0.8
    end_x = size['width'] * 0.2
    

    So the correct way to get the values from size variable is size['key'], not size.key.