title: How to get the maximum width and height coordinates of an iOS device display in Appium?
body: <p>I am using the <a href="https://github.com/appium/python-client" rel="nofollow">appium python-client</a> library to run a <a href="http://pytest.org" rel="nofollow">[py.]test</a> on iOS and Android devices. I noticed that many iOS tests crashed with <code>tap point is not within the bounds of the screen</code>. Looking into the tests is seemed weird as the supplied coordinates were seemingly within the reported bounds of the device display.</p>
  
  <p>The following snippet illustrates my problem:</p>
  
  <pre><code>from appium.webdriver.common.touch_action import TouchAction
  
  def test_max_screen_size(appium_driver):
  
      driver = appium_driver
  
      window_size = driver.get_window_size()
      max_width = window_size["width"] - 1
      max_height = window_size["height"] - 1 
  
      action = TouchAction(driver)
      action.tap(None, max_width, max_height).perform()
  </code></pre>
  
  <p>Here I am trying to tap the most <em>extreme</em> point of the display.</p>
  
  <p>This test <strong>passes</strong> on <strong>Android</strong> devices and <strong>fails</strong> on <strong>iOS</strong> simulator devices(I haven't yet tested real iOS devices - but I am certain it will also crash).</p>
  
  <p>Is this an <strong>Appium bug</strong> or am I doing something wrong?</p>
  
  <p>My environment: 
  <code>Appium 1.3.4</code>
  <code>iOS 8.1</code>
  <a href="https://github.com/appium/python-client" rel="nofollow"><code>current Appium Python client</code></a>
  <code>Python 2.7.6</code></p>
  
  <h1>Update</h1>
  
  <p>I spend a bit more time on this issue. </p>
  
  <p>First I ran this simple UIAutomation script via Instruments:</p>
  
  <pre><code>var target = UIATarget.localTarget();
  var max_width = target.rect().size.width;
  var max_height = target.rect().size.height
  
  UIALogger.logMessage("width: " + max_width + " height:" + max_height);
  
  target.tap({x:max_width, y:max_height});
  </code></pre>
  
  <p>When you run this on an iPhone 4s you get <code>max_width = 320</code> and <code>max_height = 480</code> as it is a <code>2x</code> <a href="http://www.iphoneresolution.com/" rel="nofollow">retina display</a> - exactly what Appium tells us and what is expected. </p>
  
  <p>In case you increase either variable the script will fail as expected with: <code>Script threw an uncaught JavaScript error: tap point is not within the bounds of the screen on line 8 of New Script</code>. </p>
  
  <p>This means that <strong>Appium</strong> must be sending something that <strong>Instruments</strong> does not like. </p>
  
  <p>So, the next point of failure could be the <strong>appium python client</strong>. I used <a href="https://docs.python.org/2/library/pdb.html" rel="nofollow">pdb</a> to go to the very position where the clients talks to the appium server:</p>
  
  <pre><code>../remote_connection.py(349)execute()
  -&gt; return self._request(command_info[0], url, body=data)
  (Pdb) l
  344             command_info = self._commands[command]
  345             assert command_info is not None, 'Unrecognised command %s' % command
  346             data = utils.dump_json(params)
  347             path = string.Template(command_info[1]).substitute(params)
  348             url = '%s%s' % (self._url, path)
  349  -&gt;         return self._request(command_info[0], url, body=data)
  350
  351         def _request(self, method, url, body=None):
  352             """
  353             Send an HTTP request to the remote server.
  354
  (Pdb) url
  u'http://127.0.0.1:4723/wd/hub/session/c9e49cb0-d291-4fb5-8aef-d89b9ceaa759/touch/perform'
  (Pdb) data
  '{"sessionId": "c9e49cb0-d291-4fb5-8aef-d89b9ceaa759", 
    "actions": [{"action": "tap", "options": {"y": 479, "x": 319, "count": 1}}]}'
  </code></pre>
  
  <p>This shows that also the <strong>appium python client</strong> seems to be doing what you would expect of it.</p>
  
  <p>This leaves the <strong>Appium</strong> server as next <strong>point of failure</strong>...</p>