Module: Appium::Ios

Defined in:
lib/appium_lib/ios/ios.rb,
lib/appium_lib/ios/xcuitest.rb,
lib/appium_lib/ios/element/text.rb,
lib/appium_lib/ios/common/errors.rb,
lib/appium_lib/ios/common/helper.rb,
lib/appium_lib/ios/element/alert.rb,
lib/appium_lib/ios/element/button.rb,
lib/appium_lib/ios/element/generic.rb,
lib/appium_lib/ios/xcuitest/bridge.rb,
lib/appium_lib/ios/xcuitest/helper.rb,
lib/appium_lib/ios/xcuitest/command.rb,
lib/appium_lib/ios/xcuitest/element.rb,
lib/appium_lib/ios/element/textfield.rb,
lib/appium_lib/ios/xcuitest/element/text.rb,
lib/appium_lib/ios/xcuitest/command/source.rb,
lib/appium_lib/ios/xcuitest/element/button.rb,
lib/appium_lib/ios/xcuitest/element/generic.rb,
lib/appium_lib/ios/xcuitest/command/gestures.rb,
lib/appium_lib/ios/xcuitest/element/textfield.rb,
lib/appium_lib/ios/xcuitest/command/pasteboard.rb,
lib/appium_lib/ios/xcuitest/command/certificate.rb,
lib/appium_lib/ios/xcuitest/command/get_context.rb,
lib/appium_lib/ios/xcuitest/command/multi_app_handler.rb

Defined Under Namespace

Modules: Xcuitest Classes: Bridge, CommandError, UITestElementsPrinter

Constant Summary collapse

UIAStaticText =
'UIAStaticText'.freeze
XCUIElementTypeStaticText =
'XCUIElementTypeStaticText'.freeze
UIAButton =
'UIAButton'.freeze
XCUIElementTypeButton =
'XCUIElementTypeButton'.freeze
UIATextField =
'UIATextField'.freeze
UIASecureTextField =
'UIASecureTextField'.freeze
XCUIElementTypeTextField =
'XCUIElementTypeTextField'.freeze
XCUIElementTypeSecureTextField =
'XCUIElementTypeSecureTextField'.freeze

Instance Method Summary collapse

Instance Method Details

#_all_pred(opts) ⇒ Object

predicate - the predicate to evaluate on the main app

visible - if true, only visible elements are returned. default true



362
363
364
365
366
367
368
# File 'lib/appium_lib/ios/common/helper.rb', line 362

def _all_pred(opts)
  predicate = opts[:predicate]
  raise 'predicate must be provided' unless predicate

  visible = opts.fetch :visible, true
  %($.mainApp().getAllWithPredicate("#{predicate}", #{visible});)
end

#_by_json(opts) ⇒ Object

For Appium(automation name), not XCUITest typeArray - array of string types to search for. Example: [“UIAStaticText”] onlyFirst - boolean. returns only the first result if true. Example: true onlyVisible - boolean. returns only visible elements if true. Example: true target - string. the target value to search for. Example: “Buttons, Various uses of UIButton” substring - boolean. matches on substrings if true otherwise an exact mathc is required. Example: true insensitive - boolean. ignores case sensitivity if true otherwise it’s case sensitive. Example: true

opts = {

typeArray: ["UIAStaticText"],
onlyFirst: true,
onlyVisible: true,
name: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
},
label: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
},
value: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
}

}



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/appium_lib/ios/common/helper.rb', line 441

def _by_json(opts)
  valid_keys = i(typeArray onlyFirst onlyVisible name label value)
  unknown_keys = opts.keys - valid_keys
  raise "Unknown keys: #{unknown_keys}" unless unknown_keys.empty?

  type_array = opts[:typeArray]
  raise 'typeArray must be an array' unless type_array.is_a? Array

  only_first = opts[:onlyFirst]
  raise 'onlyFirst must be a boolean' unless [true, false].include? only_first

  only_visible = opts[:onlyVisible]
  raise 'onlyVisible must be a boolean' unless [true, false].include? only_visible

  # name/label/value are optional. when searching for class only, then none
  # will be present.
  _validate_object opts[:name], opts[:label], opts[:value]

  # note that mainWindow is sometimes nil so it's passed as a param
  # $._elementOrElementsByType will validate that the window isn't nil
  element_or_elements_by_type = "    (function() {\n      var opts = \#{opts.to_json};\n      var result = false;\n\n      try {\n        result = $._elementOrElementsByType($.mainWindow(), opts);\n      } catch (e) {\n      }\n\n      return result;\n    })();\n  JS\n\n  res = execute_script element_or_elements_by_type\n  res || raise(Appium::Ios::CommandError, 'mainWindow is nil')\nend\n"

#_validate_object(*objects) ⇒ Object



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/appium_lib/ios/common/helper.rb', line 391

def _validate_object(*objects)
  raise 'objects must be an array' unless objects.is_a? Array

  objects.each do |obj|
    next unless obj # obj may be nil. if so, ignore.

    valid_keys   = i[target substring insensitive]
    unknown_keys = obj.keys - valid_keys
    raise "Unknown keys: #{unknown_keys}" unless unknown_keys.empty?

    target = obj[:target]
    raise 'target must be a string' unless target.is_a? String

    substring = obj[:substring]
    raise 'substring must be a boolean' unless [true, false].include? substring

    insensitive = obj[:insensitive]
    raise 'insensitive must be a boolean' unless [true, false].include? insensitive
  end
end

#alert_acceptvoid

This method returns an undefined value.

Accept the alert.



5
6
7
8
9
# File 'lib/appium_lib/ios/element/alert.rb', line 5

def alert_accept
  # @driver.switch_to.alert.accept
  # ".switch_to.alert" calls alert_text so use bridge directly
  driver.send(:bridge).accept_alert
end

#alert_dismissvoid

This method returns an undefined value.

Dismiss the alert.



13
14
15
16
17
# File 'lib/appium_lib/ios/element/alert.rb', line 13

def alert_dismiss
  # @driver.switch_to.alert.dismiss
  # ".switch_to.alert" calls alert_text so use bridge directly
  driver.send(:bridge).dismiss_alert
end

#button(value) ⇒ UIAButton|XCUIElementTypeButton

Find the first UIAButton|XCUIElementTypeButton that contains value or by index. If int then the UIAButton|XCUIElementTypeButton at that index is returned.

Parameters:

  • value (String, Integer)

    the value to exactly match.

Returns:



16
17
18
19
20
21
# File 'lib/appium_lib/ios/element/button.rb', line 16

def button(value)
  # return button at index.
  return ele_index button_class, value if value.is_a? Numeric

  ele_by_json_visible_contains button_class, value
end

#button_classString

Returns Class name for button.

Returns:

  • (String)

    Class name for button



8
9
10
# File 'lib/appium_lib/ios/element/button.rb', line 8

def button_class
  UIAButton
end

#button_exact(value) ⇒ UIAButton|XCUIElementTypeButton

Find the first UIAButton|XCUIElementTypeButton that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



50
51
52
# File 'lib/appium_lib/ios/element/button.rb', line 50

def button_exact(value)
  ele_by_json_visible_exact button_class, value
end

#buttons(value = false) ⇒ Array<UIAButton|XCUIElementTypeButton>

Find all UIAButtons|XCUIElementTypeButtons containing value. If value is omitted, all UIAButtons|XCUIElementTypeButtons are returned.

Parameters:

  • value (String) (defaults to: false)

    the value to search for

Returns:



27
28
29
30
31
# File 'lib/appium_lib/ios/element/button.rb', line 27

def buttons(value = false)
  return tags button_class unless value

  eles_by_json_visible_contains button_class, value
end

#buttons_exact(value) ⇒ Array<UIAButton|XCUIElementTypeButton>

Find all UIAButtons|XCUIElementTypeButtons that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



57
58
59
# File 'lib/appium_lib/ios/element/button.rb', line 57

def buttons_exact(value)
  eles_by_json_visible_exact button_class, value
end

#ele_by_json(opts) ⇒ Object

see eles_by_json



497
498
499
500
501
502
503
# File 'lib/appium_lib/ios/common/helper.rb', line 497

def ele_by_json(opts)
  opts[:onlyFirst] = true
  result = _by_json(opts).first
  raise _no_such_element if result.nil?

  result
end

#ele_by_json_visible_contains(element, value) ⇒ Element

Find the first element that contains value. For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Element)


305
306
307
# File 'lib/appium_lib/ios/common/helper.rb', line 305

def ele_by_json_visible_contains(element, value)
  ele_by_json string_visible_contains element, value
end

#ele_by_json_visible_exact(element, value) ⇒ Element

Find the first element exactly matching value For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Element)


344
345
346
# File 'lib/appium_lib/ios/common/helper.rb', line 344

def ele_by_json_visible_exact(element, value)
  ele_by_json string_visible_exact element, value
end

#ele_index(class_name, index) ⇒ Element

Get the element of type class_name at matching index.

Parameters:

  • class_name (String)

    the class name to find

  • index (Integer)

    the index

Returns:

  • (Element)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/appium_lib/ios/common/helper.rb', line 94

def ele_index(class_name, index)
  raise 'Index must be >= 1' unless index == 'last()' || (index.is_a?(Integer) && index >= 1)

  elements = tags(class_name)

  if index == 'last()'
    result = elements.last
  else
    # elements array is 0 indexed
    index -= 1
    result = elements[index]
  end

  raise _no_such_element if result.nil?

  result
end

#ele_with_pred(opts) ⇒ Element

returns element matching predicate contained in the main app

predicate - the predicate to evaluate on the main app

visible - if true, only visible elements are returned. default true

Returns:

  • (Element)


376
377
378
379
# File 'lib/appium_lib/ios/common/helper.rb', line 376

def ele_with_pred(opts)
  # true = return only visible
  find_element(:uiautomation, _all_pred(opts))
end

#eles_by_json(opts) ⇒ Object

For Appium(automation name), not XCUITest example usage:

eles_by_json({

typeArray: ["UIAStaticText"],
onlyVisible: true,
name: {
  target: "Buttons, Various uses of UIButton",
  substring: false,
  insensitive: false,
},

})



491
492
493
494
# File 'lib/appium_lib/ios/common/helper.rb', line 491

def eles_by_json(opts)
  opts[:onlyFirst] = false
  _by_json opts
end

#eles_by_json_visible_contains(element, value) ⇒ Array<Element>

Find all elements containing value For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Array<Element>)


314
315
316
# File 'lib/appium_lib/ios/common/helper.rb', line 314

def eles_by_json_visible_contains(element, value)
  eles_by_json string_visible_contains element, value
end

#eles_by_json_visible_exact(element, value) ⇒ Element

Find all elements exactly matching value For Appium(automation name), not XCUITest

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (Element)


353
354
355
# File 'lib/appium_lib/ios/common/helper.rb', line 353

def eles_by_json_visible_exact(element, value)
  eles_by_json string_visible_exact element, value
end

#eles_with_pred(opts) ⇒ Array<Element>

returns elements matching predicate contained in the main app

predicate - the predicate to evaluate on the main app

visible - if true, only visible elements are returned. default true

Returns:

  • (Array<Element>)


387
388
389
# File 'lib/appium_lib/ios/common/helper.rb', line 387

def eles_with_pred(opts)
  find_elements(:uiautomation, _all_pred(opts))
end

#find(value) ⇒ Element

Find the first element containing value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Element)


6
7
8
# File 'lib/appium_lib/ios/element/generic.rb', line 6

def find(value)
  ele_by_json_visible_contains '*', value
end

#find_ele_by_attr(class_name, attr, value) ⇒ Element

Find the first element exactly matching class and attribute value. Note: Uses XPath Note: For XCUITest, this method return ALL elements include displayed or not displayed elements.

Parameters:

  • class_name (String)

    the class name to search for

  • attr (String)

    the attribute to inspect

  • value (String)

    the expected value of the attribute

Returns:

  • (Element)


124
125
126
# File 'lib/appium_lib/ios/common/helper.rb', line 124

def find_ele_by_attr(class_name, attr, value)
  @driver.find_element :xpath, string_attr_exact(class_name, attr, value)
end

#find_ele_by_attr_include(class_name, attr, value) ⇒ Element

Get the first tag by attribute that exactly matches value. Note: Uses XPath

Parameters:

  • class_name (String)

    the tag name to match

  • attr (String)

    the attribute to compare

  • value (String)

    the value of the attribute that the element must include

Returns:

  • (Element)

    the element of type tag who’s attribute includes value



176
177
178
# File 'lib/appium_lib/ios/common/helper.rb', line 176

def find_ele_by_attr_include(class_name, attr, value)
  @driver.find_element :xpath, string_attr_include(class_name, attr, value)
end

#find_ele_by_predicate(class_name: '*', value:) ⇒ Element

Find the first element exactly matching attribute case insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the expected value of the attribute

Returns:

  • (Element)


148
149
150
151
152
153
# File 'lib/appium_lib/ios/common/helper.rb', line 148

def find_ele_by_predicate(class_name: '*', value:)
  elements = find_eles_by_predicate(class_name: class_name, value: value)
  raise _no_such_element if elements.empty?

  elements.first
end

#find_ele_by_predicate_include(class_name: '*', value:) ⇒ Element

Get the first elements that include insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the value of the attribute that the element must include

Returns:

  • (Element)

    the element of type tag who’s attribute includes value



194
195
196
197
198
199
# File 'lib/appium_lib/ios/common/helper.rb', line 194

def find_ele_by_predicate_include(class_name: '*', value:)
  elements = find_eles_by_predicate_include(class_name: class_name, value: value)
  raise _no_such_element if elements.empty?

  elements.first
end

#find_eles_by_attr(class_name, attr, value) ⇒ Array<Element>

Find all elements exactly matching class and attribute value. Note: Uses XPath Note: For XCUITest, this method return ALL elements include displayed or not displayed elements.

Parameters:

  • class_name (String)

    the class name to match

  • attr (String)

    the attribute to compare

  • value (String)

    the value of the attribute that the element must have

Returns:

  • (Array<Element>)


135
136
137
# File 'lib/appium_lib/ios/common/helper.rb', line 135

def find_eles_by_attr(class_name, attr, value)
  @driver.find_elements :xpath, string_attr_exact(class_name, attr, value)
end

#find_eles_by_attr_include(class_name, attr, value) ⇒ Array<Element>

Get tags by attribute that include value. Note: Uses XPath

Parameters:

  • class_name (String)

    the tag name to match

  • attr (String)

    the attribute to compare

  • value (String)

    the value of the attribute that the element must include

Returns:

  • (Array<Element>)

    the elements of type tag who’s attribute includes value



186
187
188
# File 'lib/appium_lib/ios/common/helper.rb', line 186

def find_eles_by_attr_include(class_name, attr, value)
  @driver.find_elements :xpath, string_attr_include(class_name, attr, value)
end

#find_eles_by_predicate(class_name: '*', value:) ⇒ Array<Element>

Find all elements exactly matching attribute case insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the value of the attribute that the element must have

  • class_name (String) (defaults to: '*')

    the tag name to match

Returns:

  • (Array<Element>)


160
161
162
163
164
165
166
167
168
# File 'lib/appium_lib/ios/common/helper.rb', line 160

def find_eles_by_predicate(class_name: '*', value:)
  predicate = if class_name == '*'
                %(name == "#{value}" || label == "#{value}" || value == "#{value}")
              else
                %(type == "#{class_name}" && ) +
                  %((name == "#{value}" || label == "#{value}" || value == "#{value}"))
              end
  @driver.find_elements :predicate, predicate
end

#find_eles_by_predicate_include(class_name: '*', value:) ⇒ Array<Element>

Get elements that include case insensitive value. Note: Uses Predicate

Parameters:

  • value (String)

    the value of the attribute that the element must include

  • class_name (String) (defaults to: '*')

    the tag name to match

Returns:

  • (Array<Element>)

    the elements of type tag who’s attribute includes value



206
207
208
209
210
211
212
213
214
# File 'lib/appium_lib/ios/common/helper.rb', line 206

def find_eles_by_predicate_include(class_name: '*', value:)
  predicate = if class_name == '*'
                %(name contains[c] "#{value}" || label contains[c] "#{value}" || value contains[c] "#{value}")
              else
                %(type == "#{class_name}" && ) +
                  %((name contains[c] "#{value}" || label contains[c] "#{value}" || value contains[c] "#{value}"))
              end
  @driver.find_elements :predicate, predicate
end

#find_exact(value) ⇒ Element

Find the first element exactly matching value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Element)


20
21
22
# File 'lib/appium_lib/ios/element/generic.rb', line 20

def find_exact(value)
  ele_by_json_visible_exact '*', value
end

#finds(value) ⇒ Array<Element>

Find all elements containing value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Array<Element>)


13
14
15
# File 'lib/appium_lib/ios/element/generic.rb', line 13

def finds(value)
  eles_by_json_visible_contains '*', value
end

#finds_exact(value) ⇒ Array<Element>

Find all elements exactly matching value

Parameters:

  • value (String)

    the value to search for

Returns:

  • (Array<Element>)


27
28
29
# File 'lib/appium_lib/ios/element/generic.rb', line 27

def finds_exact(value)
  eles_by_json_visible_exact '*', value
end

#first_buttonUIAButton|XCUIElementTypeButton

Find the first UIAButton|XCUIElementTypeButton.



35
36
37
# File 'lib/appium_lib/ios/element/button.rb', line 35

def first_button
  first_ele button_class
end

#first_ele(class_name) ⇒ Element

Get the first tag that matches class_name

Parameters:

  • class_name (String)

    the tag to match

Returns:

  • (Element)


219
220
221
# File 'lib/appium_lib/ios/common/helper.rb', line 219

def first_ele(class_name)
  ele_index class_name, 1
end

#first_textUIAStaticText|XCUIElementTypeStaticText

Find the first UIAStaticText|XCUIElementTypeStaticText.



34
35
36
# File 'lib/appium_lib/ios/element/text.rb', line 34

def first_text
  first_ele static_text_class
end

#first_textfieldTextField

Find the first TextField.

Returns:

  • (TextField)


51
52
53
# File 'lib/appium_lib/ios/element/textfield.rb', line 51

def first_textfield
  ele_by_json _textfield_visible
end

#id(id) ⇒ Element

Find by id

Parameters:

  • id (String)

    the id to search for

Returns:

  • (Element)


86
87
88
# File 'lib/appium_lib/ios/common/helper.rb', line 86

def id(id)
  find_element(:id, id)
end

#ios_password(length = 1) ⇒ String

iOS only. On Android uiautomator always returns an empty string for EditText password.

Password character returned from value of UIASecureTextField

Parameters:

  • length (Integer) (defaults to: 1)

    the length of the password to generate

Returns:

  • (String)

    the returned string is of size length



43
44
45
# File 'lib/appium_lib/ios/common/helper.rb', line 43

def ios_password(length = 1)
  8226.chr('UTF-8') * length
end

#last_buttonUIAButton|XCUIElementTypeButton

TODO: add documentation regarding previous element.

Previous UIAElement is differ from UIAButton|XCUIElementTypeButton. So, the results are different.

Find the last UIAButton|XCUIElementTypeButton.



43
44
45
# File 'lib/appium_lib/ios/element/button.rb', line 43

def last_button
  last_ele button_class
end

#last_ele(class_name) ⇒ Element

Get the last tag that matches class_name

Parameters:

  • class_name (String)

    the tag to match

Returns:

  • (Element)


226
227
228
# File 'lib/appium_lib/ios/common/helper.rb', line 226

def last_ele(class_name)
  ele_index class_name, 'last()'
end

#last_textUIAStaticText|XCUIElementTypeStaticText

Find the last UIAStaticText|XCUIElementTypeStaticText.



40
41
42
# File 'lib/appium_lib/ios/element/text.rb', line 40

def last_text
  last_ele static_text_class
end

#last_textfieldTextField

Find the last TextField.

Returns:

  • (TextField)


57
58
59
60
61
62
# File 'lib/appium_lib/ios/element/textfield.rb', line 57

def last_textfield
  result = eles_by_json(_textfield_visible).last
  raise _no_such_element if result.nil?

  result
end

#page(opts = {}) ⇒ void

This method returns an undefined value.

Prints a string of interesting elements to the console.

Examples:

```ruby
page class: :UIAButton # filter on buttons
page class: :UIAButton, window: 1
```

Parameters:

  • visible (Hash)

    a customizable set of options

  • class (Hash)

    a customizable set of options



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/appium_lib/ios/common/helper.rb', line 59

def page(opts = {})
  class_name = opts.is_a?(Hash) ? opts.fetch(:class, nil) : opts

  source = get_source

  # current_context may be nil which breaks start_with
  if current_context && current_context.start_with?('WEBVIEW')
    parser = @android_html_parser ||= Nokogiri::HTML::SAX::Parser.new(Appium::Common::HTMLElements.new)
    parser.document.reset
    parser.document.filter = class_name
    parser.parse source
    result = parser.document.result
    puts result
    result
  else
    parser = Nokogiri::XML::SAX::Parser.new(UITestElementsPrinter.new)
    if class_name
      parser.document.filter = class_name.is_a?(Symbol) ? class_name.to_s : class_name
    end
    parser.parse source
    nil
  end
end

#secure_text_field_classString

Returns Class name for secure text field.

Returns:

  • (String)

    Class name for secure text field



15
16
17
# File 'lib/appium_lib/ios/element/textfield.rb', line 15

def secure_text_field_class
  UIASecureTextField
end

#static_text_classString

Returns Class name for text.

Returns:

  • (String)

    Class name for text



8
9
10
# File 'lib/appium_lib/ios/element/text.rb', line 8

def static_text_class
  UIAStaticText
end

#string_attr_exact(class_name, attr, value) ⇒ Object



113
114
115
# File 'lib/appium_lib/ios/common/helper.rb', line 113

def string_attr_exact(class_name, attr, value)
  %(//#{class_name}[@visible="true" and @#{attr}="#{value}"])
end

#string_attr_include(class_name, attr, value) ⇒ Object



140
141
142
# File 'lib/appium_lib/ios/common/helper.rb', line 140

def string_attr_include(class_name, attr, value)
  %(//#{class_name}[@visible="true" and contains(translate(@#{attr},"#{value.upcase}", "#{value}"), "#{value}")])
end

#string_visible_contains(element, value) ⇒ String

Returns an object that matches the first element that contains value

example: ele_by_json_visible_contains ‘UIATextField’, ‘sign in’

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (String)


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/appium_lib/ios/common/helper.rb', line 284

def string_visible_contains(element, value)
  contains = {
    target: value,
    substring: true,
    insensitive: true
  }

  {
    typeArray: [element],
    onlyVisible: true,
    name: contains,
    label: contains,
    value: contains
  }
end

#string_visible_exact(element, value) ⇒ String

Create an object to exactly match the first element with target value

Parameters:

  • element (String)

    the class name for the element

  • value (String)

    the value to search for

Returns:

  • (String)


323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/appium_lib/ios/common/helper.rb', line 323

def string_visible_exact(element, value)
  exact = {
    target: value,
    substring: false,
    insensitive: false
  }

  {
    typeArray: [element],
    onlyVisible: true,
    name: exact,
    label: exact,
    value: exact
  }
end

#tag(class_name) ⇒ Element

Returns the first visible element matching class_name

Parameters:

  • class_name (String)

    the class_name to search for

Returns:

  • (Element)


234
235
236
# File 'lib/appium_lib/ios/common/helper.rb', line 234

def tag(class_name)
  ele_by_json(typeArray: [class_name], onlyVisible: true)
end

#tags(class_name) ⇒ Element

Returns all visible elements matching class_name

Parameters:

  • class_name (String)

    the class_name to search for

Returns:

  • (Element)


242
243
244
# File 'lib/appium_lib/ios/common/helper.rb', line 242

def tags(class_name)
  eles_by_json(typeArray: [class_name], onlyVisible: true)
end

#tags_exact(class_names:, value: nil) ⇒ Array[Element]

Returns all visible elements matching class_names and value. This method calls find_element/s and element.value/text many times. So, if you set many class_names, this method’s performance become worse.

Parameters:

  • class_names (Array[String])

    the class_names to search for

  • value (String) (defaults to: nil)

    the value to search for

Returns:

  • (Array[Element])


268
269
270
271
272
273
274
# File 'lib/appium_lib/ios/common/helper.rb', line 268

def tags_exact(class_names:, value: nil)
  return unless class_names.is_a? Array

  class_names.flat_map do |class_name|
    value ? eles_by_json_visible_exact(class_name, value) : tags(class_name)
  end
end

#tags_include(class_names:, value: nil) ⇒ Array[Element]

Returns all visible elements matching class_names and value This method calls find_element/s and element.value/text many times. So, if you set many class_names, this method’s performance become worse.

Parameters:

  • class_names (Array[String])

    the class_names to search for

  • value (String) (defaults to: nil)

    the value to search for

Returns:

  • (Array[Element])


253
254
255
256
257
258
259
# File 'lib/appium_lib/ios/common/helper.rb', line 253

def tags_include(class_names:, value: nil)
  return unless class_names.is_a? Array

  class_names.flat_map do |class_name|
    value ? eles_by_json_visible_contains(class_name, value) : tags(class_name)
  end
end

#text(value) ⇒ UIAStaticText|XCUIElementTypeStaticText

Find the first UIAStaticText|XCUIElementTypeStaticText that contains value or by index. If int then the UIAStaticText|XCUIElementTypeStaticText at that index is returned.

Parameters:

  • value (String, Integer)

    the value to find.

Returns:



16
17
18
19
20
# File 'lib/appium_lib/ios/element/text.rb', line 16

def text(value)
  return ele_index static_text_class, value if value.is_a? Numeric

  ele_by_json_visible_contains static_text_class, value
end

#text_exact(value) ⇒ UIAStaticText|XCUIElementTypeStaticText

Find the first UIAStaticText|XCUIElementTypeStaticText that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



47
48
49
# File 'lib/appium_lib/ios/element/text.rb', line 47

def text_exact(value)
  ele_by_json_visible_exact static_text_class, value
end

#text_field_classString

Returns Class name for text field.

Returns:

  • (String)

    Class name for text field



10
11
12
# File 'lib/appium_lib/ios/element/textfield.rb', line 10

def text_field_class
  UIATextField
end

#textfield(value) ⇒ TextField

Find the first TextField that contains value or by index. Note: Uses XPath If int then the TextField at that index is returned.

Parameters:

  • value (String, Integer)

    the text to match exactly.

Returns:

  • (TextField)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/appium_lib/ios/element/textfield.rb', line 24

def textfield(value)
  if value.is_a? Numeric
    index = value
    raise "#{index} is not a valid index. Must be >= 1" if index <= 0

    index -= 1 # eles_by_json and _textfields_with_predicate is 0 indexed.
    result = eles_by_json(_textfield_visible)[index]
    raise _no_such_element if result.nil?

    return result
  end

  ele_by_json _textfield_contains_string value
end

#textfield_exact(value) ⇒ TextField

Find the first TextField that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:

  • (TextField)


67
68
69
# File 'lib/appium_lib/ios/element/textfield.rb', line 67

def textfield_exact(value)
  ele_by_json _textfield_exact_string value
end

#textfields(value = false) ⇒ Array<TextField>

Find all TextFields containing value. If value is omitted, all TextFields are returned.

Parameters:

  • value (String) (defaults to: false)

    the value to search for

Returns:

  • (Array<TextField>)


43
44
45
46
47
# File 'lib/appium_lib/ios/element/textfield.rb', line 43

def textfields(value = false)
  return eles_by_json _textfield_visible unless value

  eles_by_json _textfield_contains_string value
end

#textfields_exact(value) ⇒ Array<TextField>

Find all TextFields that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:

  • (Array<TextField>)


74
75
76
# File 'lib/appium_lib/ios/element/textfield.rb', line 74

def textfields_exact(value)
  eles_by_json _textfield_exact_string value
end

#texts(value = false) ⇒ Array<UIAStaticText|XCUIElementTypeStaticText>

Find all UIAStaticTexts|XCUIElementTypeStaticTexts containing value. If value is omitted, all UIAStaticTexts|XCUIElementTypeStaticTexts are returned

Parameters:

  • value (String) (defaults to: false)

    the value to search for

Returns:



26
27
28
29
30
# File 'lib/appium_lib/ios/element/text.rb', line 26

def texts(value = false)
  return tags static_text_class unless value

  eles_by_json_visible_contains static_text_class, value
end

#texts_exact(value) ⇒ Array<UIAStaticText|XCUIElementTypeStaticText>

Find all UIAStaticTexts|XCUIElementTypeStaticTexts that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



54
55
56
# File 'lib/appium_lib/ios/element/text.rb', line 54

def texts_exact(value)
  eles_by_json_visible_exact static_text_class, value
end