14
14
15
15
from selenium .webdriver .common .by import By
16
16
from selenium .webdriver .remote .webelement import WebElement as SeleniumWebElement
17
+ from selenium .webdriver .remote .command import Command as RemoteCommand
18
+
19
+ from appium .webdriver .common .mobileby import MobileBy
17
20
18
21
from .mobilecommand import MobileCommand as Command
19
22
@@ -28,7 +31,7 @@ def find_element_by_ios_uiautomation(self, uia_string):
28
31
:Usage:
29
32
driver.find_element_by_ios_uiautomation('.elements()[1].cells()[2]')
30
33
"""
31
- return self .find_element (by = By .IOS_UIAUTOMATION , value = uia_string )
34
+ return self .find_element (by = MobileBy .IOS_UIAUTOMATION , value = uia_string )
32
35
33
36
def find_elements_by_ios_uiautomation (self , uia_string ):
34
37
"""Finds elements by uiautomation in iOS.
@@ -39,7 +42,7 @@ def find_elements_by_ios_uiautomation(self, uia_string):
39
42
:Usage:
40
43
driver.find_elements_by_ios_uiautomation('.elements()[1].cells()[2]')
41
44
"""
42
- return self .find_elements (by = By .IOS_UIAUTOMATION , value = uia_string )
45
+ return self .find_elements (by = MobileBy .IOS_UIAUTOMATION , value = uia_string )
43
46
44
47
def find_element_by_ios_predicate (self , predicate_string ):
45
48
"""Find an element by ios predicate string.
@@ -50,7 +53,7 @@ def find_element_by_ios_predicate(self, predicate_string):
50
53
:Usage:
51
54
driver.find_element_by_ios_predicate('label == "myLabel"')
52
55
"""
53
- return self .find_element (by = By .IOS_PREDICATE , value = predicate_string )
56
+ return self .find_element (by = MobileBy .IOS_PREDICATE , value = predicate_string )
54
57
55
58
def find_elements_by_ios_predicate (self , predicate_string ):
56
59
"""Finds elements by ios predicate string.
@@ -61,7 +64,7 @@ def find_elements_by_ios_predicate(self, predicate_string):
61
64
:Usage:
62
65
driver.find_elements_by_ios_predicate('label == "myLabel"')
63
66
"""
64
- return self .find_elements (by = By .IOS_PREDICATE , value = predicate_string )
67
+ return self .find_elements (by = MobileBy .IOS_PREDICATE , value = predicate_string )
65
68
66
69
def find_element_by_ios_class_chain (self , class_chain_string ):
67
70
"""Find an element by ios class chain string.
@@ -72,7 +75,7 @@ def find_element_by_ios_class_chain(self, class_chain_string):
72
75
:Usage:
73
76
driver.find_element_by_ios_class_chain('XCUIElementTypeWindow/XCUIElementTypeButton[3]')
74
77
"""
75
- return self .find_element (by = By .IOS_CLASS_CHAIN , value = class_chain_string )
78
+ return self .find_element (by = MobileBy .IOS_CLASS_CHAIN , value = class_chain_string )
76
79
77
80
def find_elements_by_ios_class_chain (self , class_chain_string ):
78
81
"""Finds elements by ios class chain string.
@@ -83,7 +86,7 @@ def find_elements_by_ios_class_chain(self, class_chain_string):
83
86
:Usage:
84
87
driver.find_elements_by_ios_class_chain('XCUIElementTypeWindow[2]/XCUIElementTypeAny[-2]')
85
88
"""
86
- return self .find_elements (by = By .IOS_CLASS_CHAIN , value = class_chain_string )
89
+ return self .find_elements (by = MobileBy .IOS_CLASS_CHAIN , value = class_chain_string )
87
90
88
91
def find_element_by_android_uiautomator (self , uia_string ):
89
92
"""Finds element by uiautomator in Android.
@@ -94,7 +97,7 @@ def find_element_by_android_uiautomator(self, uia_string):
94
97
:Usage:
95
98
driver.find_element_by_android_uiautomator('.elements()[1].cells()[2]')
96
99
"""
97
- return self .find_element (by = By .ANDROID_UIAUTOMATOR , value = uia_string )
100
+ return self .find_element (by = MobileBy .ANDROID_UIAUTOMATOR , value = uia_string )
98
101
99
102
def find_elements_by_android_uiautomator (self , uia_string ):
100
103
"""Finds elements by uiautomator in Android.
@@ -105,7 +108,7 @@ def find_elements_by_android_uiautomator(self, uia_string):
105
108
:Usage:
106
109
driver.find_elements_by_android_uiautomator('.elements()[1].cells()[2]')
107
110
"""
108
- return self .find_elements (by = By .ANDROID_UIAUTOMATOR , value = uia_string )
111
+ return self .find_elements (by = MobileBy .ANDROID_UIAUTOMATOR , value = uia_string )
109
112
110
113
def find_element_by_accessibility_id (self , accessibility_id ):
111
114
"""Finds an element by accessibility id.
@@ -117,7 +120,7 @@ def find_element_by_accessibility_id(self, accessibility_id):
117
120
:Usage:
118
121
driver.find_element_by_accessibility_id()
119
122
"""
120
- return self .find_element (by = By .ACCESSIBILITY_ID , value = accessibility_id )
123
+ return self .find_element (by = MobileBy .ACCESSIBILITY_ID , value = accessibility_id )
121
124
122
125
def find_elements_by_accessibility_id (self , accessibility_id ):
123
126
"""Finds elements by accessibility id.
@@ -129,7 +132,57 @@ def find_elements_by_accessibility_id(self, accessibility_id):
129
132
:Usage:
130
133
driver.find_elements_by_accessibility_id()
131
134
"""
132
- return self .find_elements (by = By .ACCESSIBILITY_ID , value = accessibility_id )
135
+ return self .find_elements (by = MobileBy .ACCESSIBILITY_ID , value = accessibility_id )
136
+
137
+ def find_element (self , by = By .ID , value = None ):
138
+ """
139
+ Find an element given a By strategy and locator. Prefer the find_element_by_* methods when
140
+ possible.
141
+ :Usage:
142
+ element = element.find_element(By.ID, 'foo')
143
+ :rtype: WebElement
144
+ """
145
+ # TODO: If we need, we should enable below converter for Web context
146
+ # if self._w3c:
147
+ # if by == By.ID:
148
+ # by = By.CSS_SELECTOR
149
+ # value = '[id="%s"]' % value
150
+ # elif by == By.TAG_NAME:
151
+ # by = By.CSS_SELECTOR
152
+ # elif by == By.CLASS_NAME:
153
+ # by = By.CSS_SELECTOR
154
+ # value = ".%s" % value
155
+ # elif by == By.NAME:
156
+ # by = By.CSS_SELECTOR
157
+ # value = '[name="%s"]' % value
158
+
159
+ return self ._execute (RemoteCommand .FIND_CHILD_ELEMENT ,
160
+ {"using" : by , "value" : value })['value' ]
161
+
162
+ def find_elements (self , by = By .ID , value = None ):
163
+ """
164
+ Find elements given a By strategy and locator. Prefer the find_elements_by_* methods when
165
+ possible.
166
+ :Usage:
167
+ element = element.find_elements(By.CLASS_NAME, 'foo')
168
+ :rtype: list of WebElement
169
+ """
170
+ # TODO: If we need, we should enable below converter for Web context
171
+ # if self._w3c:
172
+ # if by == By.ID:
173
+ # by = By.CSS_SELECTOR
174
+ # value = '[id="%s"]' % value
175
+ # elif by == By.TAG_NAME:
176
+ # by = By.CSS_SELECTOR
177
+ # elif by == By.CLASS_NAME:
178
+ # by = By.CSS_SELECTOR
179
+ # value = ".%s" % value
180
+ # elif by == By.NAME:
181
+ # by = By.CSS_SELECTOR
182
+ # value = '[name="%s"]' % value
183
+
184
+ return self ._execute (RemoteCommand .FIND_CHILD_ELEMENTS ,
185
+ {"using" : by , "value" : value })['value' ]
133
186
134
187
def set_text (self , keys = '' ):
135
188
"""Sends text to the element. Previous text is removed.
0 commit comments