Skip to content

Commit 05507ee

Browse files
committed
Add el.location_in_view method
1 parent 5b6ab72 commit 05507ee

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MobileCommand(object):
2828
DEACTIVATE_IME_ENGINE = 'deactivateIMEEngine'
2929
GET_ACTIVE_IME_ENGINE = 'getActiveEngine'
3030
TOGGLE_LOCATION_SERVICES = 'toggleLocationServices'
31+
LOCATION_IN_VIEW = 'locationInView'
3132

3233
# Appium Commands
3334
GET_APP_STRINGS = 'getAppStrings'

appium/webdriver/webdriver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ def _addCommands(self):
782782
self.command_executor._commands[Command.GET_ACTIVE_IME_ENGINE] = \
783783
('GET', '/session/$sessionId/ime/active_engine')
784784
self.command_executor._commands[Command.REPLACE_KEYS] = \
785-
('POST', '/session/$sessionId/appium/element/$elementId/replace_value')
785+
('POST', '/session/$sessionId/appium/element/$id/replace_value')
786786
self.command_executor._commands[Command.GET_SETTINGS] = \
787787
('GET', '/session/$sessionId/appium/settings')
788788
self.command_executor._commands[Command.UPDATE_SETTINGS] = \
@@ -791,6 +791,8 @@ def _addCommands(self):
791791
('POST', '/session/$sessionId/appium/device/toggle_location_services')
792792
self.command_executor._commands[Command.SET_LOCATION] = \
793793
('POST', '/session/$sessionId/location')
794+
self.command_executor._commands[Command.LOCATION_IN_VIEW] = \
795+
('GET', '/session/$sessionId/element/$id/location_in_view')
794796

795797

796798
# monkeypatched method for WebElement

appium/webdriver/webelement.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@ def set_text(self, keys=''):
103103
}
104104
self._execute(Command.REPLACE_KEYS, data)
105105
return self
106+
107+
@property
108+
def location_in_view(self):
109+
"""Gets the location of an element relative to the view.
110+
111+
:Usage:
112+
location = element.location_in_view
113+
"""
114+
return self._execute(Command.LOCATION_IN_VIEW)['value']

test/functional/android/appium_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ def test_update_settings(self):
220220
def test_toggle_location_services(self):
221221
self.driver.toggle_location_services()
222222

223+
def test_element_location_in_view(self):
224+
el = self.driver.find_element_by_name('Content')
225+
loc = el.location_in_view
226+
self.assertIsNotNone(loc['x'])
227+
self.assertIsNotNone(loc['y'])
228+
223229

224230
if __name__ == "__main__":
225231
suite = unittest.TestLoader().loadTestsFromTestCase(AppiumTests)

0 commit comments

Comments
 (0)