@@ -229,17 +229,18 @@ def ele_index(class_name, index)
229
229
def string_attr_exact ( class_name , attr , value )
230
230
if automation_name_is_xcuitest?
231
231
if attr == '*'
232
- %((//#{ class_name } )[@*[.=' #{ value } ' ]])
232
+ %((//#{ class_name } )[@*[.=" #{ value } " ]])
233
233
else
234
- %((//#{ class_name } )[@#{ attr } =' #{ value } ' ])
234
+ %((//#{ class_name } )[@#{ attr } =" #{ value } " ])
235
235
end
236
236
else
237
- %(//#{ class_name } [@visible="true" and @#{ attr } =' #{ value } ' ])
237
+ %(//#{ class_name } [@visible="true" and @#{ attr } =" #{ value } " ])
238
238
end
239
239
end
240
240
241
241
# Find the first element exactly matching class and attribute value.
242
242
# Note: Uses XPath
243
+ # Note: For XCUITest, this method return ALL elements include displayed or not displayed elements.
243
244
# @param class_name [String] the class name to search for
244
245
# @param attr [String] the attribute to inspect
245
246
# @param value [String] the expected value of the attribute
@@ -250,6 +251,7 @@ def find_ele_by_attr(class_name, attr, value)
250
251
251
252
# Find all elements exactly matching class and attribute value.
252
253
# Note: Uses XPath
254
+ # Note: For XCUITest, this method return ALL elements include displayed or not displayed elements.
253
255
# @param class_name [String] the class name to match
254
256
# @param attr [String] the attribute to compare
255
257
# @param value [String] the value of the attribute that the element must have
@@ -262,12 +264,12 @@ def find_eles_by_attr(class_name, attr, value)
262
264
def string_attr_include ( class_name , attr , value )
263
265
if automation_name_is_xcuitest?
264
266
if attr == '*'
265
- %((//#{ class_name } )[@*[contains(translate(., ' #{ value . upcase } ', ' #{ value } ' ), ' #{ value } ' )]])
267
+ %((//#{ class_name } )[@*[contains(translate(., " #{ value . upcase } ", " #{ value } " ), " #{ value } " )]])
266
268
else
267
- %((//#{ class_name } )[contains(translate(@#{ attr } , ' #{ value . upcase } ', ' #{ value } ' ), ' #{ value } ' )])
269
+ %((//#{ class_name } )[contains(translate(@#{ attr } , " #{ value . upcase } ", " #{ value } " ), " #{ value } " )])
268
270
end
269
271
else
270
- %(//#{ class_name } [@visible="true" and contains(translate(@#{ attr } ,' #{ value . upcase } ', ' #{ value } ' ), ' #{ value } ' )])
272
+ %(//#{ class_name } [@visible="true" and contains(translate(@#{ attr } ," #{ value . upcase } ", " #{ value } " ), " #{ value } " )])
271
273
end
272
274
end
273
275
@@ -295,33 +297,29 @@ def find_eles_by_attr_include(class_name, attr, value)
295
297
# @param class_name [String] the tag to match
296
298
# @return [Element]
297
299
def first_ele ( class_name )
298
- if automation_name_is_xcuitest?
299
- @driver . find_element :class , class_name
300
- else
301
- ele_index class_name , 1
302
- end
300
+ ele_index class_name , 1
303
301
end
304
302
305
303
# Get the last tag that matches class_name
306
304
# @param class_name [String] the tag to match
307
305
# @return [Element]
308
306
def last_ele ( class_name )
309
307
if automation_name_is_xcuitest?
310
- result = @driver . find_elements :xpath , "(// #{ class_name } )"
311
- raise _no_such_element if result . empty?
312
- result . last
308
+ visible_elements = tags class_name
309
+ raise _no_such_element if visible_elements . empty?
310
+ visible_elements . last
313
311
else
314
312
ele_index class_name , 'last()'
315
313
end
316
314
end
317
315
318
- # Returns the first visible element matching class_name
316
+ # Returns the first ** visible** element matching class_name
319
317
#
320
318
# @param class_name [String] the class_name to search for
321
319
# @return [Element]
322
320
def tag ( class_name )
323
321
if automation_name_is_xcuitest?
324
- first_ele ( class_name )
322
+ raise_error_if_no_element tags ( class_name ) . first
325
323
else
326
324
ele_by_json ( typeArray : [ class_name ] , onlyVisible : true )
327
325
end
@@ -333,7 +331,8 @@ def tag(class_name)
333
331
# @return [Element]
334
332
def tags ( class_name )
335
333
if automation_name_is_xcuitest?
336
- @driver . find_elements :class , class_name
334
+ elements = @driver . find_elements :class , class_name
335
+ select_visible_elements elements
337
336
else
338
337
eles_by_json ( typeArray : [ class_name ] , onlyVisible : true )
339
338
end
0 commit comments