Skip to content

Commit c5a0043

Browse files
committed
Added clear to driver.
Added find elements by ios predicate string.
1 parent 399f800 commit c5a0043

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

appium/webdriver/common/mobileby.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
class MobileBy(By):
19+
IOS_PREDICATE = '-ios predicate string'
1920
IOS_UIAUTOMATION = '-ios uiautomation'
2021
ANDROID_UIAUTOMATOR = '-android uiautomator'
2122
ACCESSIBILITY_ID = 'accessibility id'

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ class MobileCommand(object):
5858
UPDATE_SETTINGS = 'updateSettings'
5959
SET_LOCATION = 'setLocation'
6060
GET_DEVICE_TIME = 'getDeviceTime'
61+
CLEAR = 'clear'

appium/webdriver/webdriver.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
4343

4444
# add new method to the `find_by_*` pantheon
4545
By.IOS_UIAUTOMATION = MobileBy.IOS_UIAUTOMATION
46+
By.IOS_PREDICATE = MobileBy.IOS_PREDICATE
4647
By.ANDROID_UIAUTOMATOR = MobileBy.ANDROID_UIAUTOMATOR
4748
By.ACCESSIBILITY_ID = MobileBy.ACCESSIBILITY_ID
4849

@@ -98,6 +99,28 @@ def find_elements_by_ios_uiautomation(self, uia_string):
9899
"""
99100
return self.find_elements(by=By.IOS_UIAUTOMATION, value=uia_string)
100101

102+
def find_element_by_ios_predicate(self, predicate_string):
103+
"""Find an element by ios predicate string.
104+
105+
:Args:
106+
- predicate_string - The predicate string
107+
108+
:Usage:
109+
driver.find_element_by_ios_predicate('label == "myLabel"')
110+
"""
111+
return self.find_element(by=By.IOS_PREDICATE, value=predicate_string)
112+
113+
def find_elements_by_ios_predicate(self, predicate_string):
114+
"""Finds elements by ios predicate string.
115+
116+
:Args:
117+
- predicate_string - The predicate string
118+
119+
:Usage:
120+
driver.find_elements_by_ios_predicate('label == "myLabel"')
121+
"""
122+
return self.find_elements(by=By.IOS_PREDICATE, value=predicate_string)
123+
101124
def find_element_by_android_uiautomator(self, uia_string):
102125
"""Finds element by uiautomator in Android.
103126
@@ -829,3 +852,5 @@ def _addCommands(self):
829852
('GET', '/session/$sessionId/element/$id/location_in_view')
830853
self.command_executor._commands[Command.GET_DEVICE_TIME] = \
831854
('GET', '/session/$sessionId/appium/device/system_time')
855+
self.command_executor._commands[Command.CLEAR] = \
856+
('POST', '/session/$sessionId/element/$id/clear')

appium/webdriver/webelement.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ def find_elements_by_ios_uiautomation(self, uia_string):
4141
"""
4242
return self.find_elements(by=By.IOS_UIAUTOMATION, value=uia_string)
4343

44+
def find_element_by_ios_predicate(self, predicate_string):
45+
"""Find an element by ios predicate string.
46+
47+
:Args:
48+
- predicate_string - The predicate string
49+
50+
:Usage:
51+
driver.find_element_by_ios_predicate('label == "myLabel"')
52+
"""
53+
return self.find_element(by=By.IOS_PREDICATE, value=predicate_string)
54+
55+
def find_elements_by_ios_predicate(self, predicate_string):
56+
"""Finds elements by ios predicate string.
57+
58+
:Args:
59+
- predicate_string - The predicate string
60+
61+
:Usage:
62+
driver.find_elements_by_ios_predicate('label == "myLabel"')
63+
"""
64+
return self.find_elements(by=By.IOS_PREDICATE, value=predicate_string)
65+
4466
def find_element_by_android_uiautomator(self, uia_string):
4567
"""Finds element by uiautomator in Android.
4668
@@ -122,3 +144,10 @@ def set_value(self, value):
122144
}
123145
self._execute(Command.SET_IMMEDIATE_VALUE, data)
124146
return self
147+
148+
def clear(self):
149+
"""Clears text.
150+
"""
151+
data = {'id': self.id}
152+
self._execute(Command.CLEAR, data)
153+
return self

0 commit comments

Comments
 (0)