Module: Appium::Ios::Xcuitest::Element

Defined in:
lib/appium_lib/ios/xcuitest/element.rb,
lib/appium_lib/ios/xcuitest/element/text.rb,
lib/appium_lib/ios/xcuitest/element/button.rb,
lib/appium_lib/ios/xcuitest/element/generic.rb,
lib/appium_lib/ios/xcuitest/element/textfield.rb

Instance Method Summary collapse

Instance Method Details

#button(value) ⇒ UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

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:



31
32
33
34
35
36
# File 'lib/appium_lib/ios/xcuitest/element/button.rb', line 31

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

  raise_error_if_no_element buttons(value).first
end

#button_classString

Returns Class name for button.

Returns:

  • (String)

    Class name for button



23
24
25
# File 'lib/appium_lib/ios/xcuitest/element/button.rb', line 23

def button_class
  ::Appium::Ios::XCUIELEMENT_TYPE_BUTTON
end

#button_exact(value) ⇒ UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

Find the first UIAButton|XCUIElementTypeButton that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



66
67
68
# File 'lib/appium_lib/ios/xcuitest/element/button.rb', line 66

def button_exact(value)
  raise_error_if_no_element buttons_exact(value).first
end

#buttons(value = false) ⇒ Array<UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON>

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:



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

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

  elements = find_eles_by_predicate_include(class_name: button_class, value: value)
  select_visible_elements elements
end

#buttons_exact(value) ⇒ Array<UIA_BUTTON|XCUIELEMENT_TYPE_BUTTON>

Find all UIAButtons|XCUIElementTypeButtons that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



73
74
75
76
# File 'lib/appium_lib/ios/xcuitest/element/button.rb', line 73

def buttons_exact(value)
  elements = find_eles_by_predicate(class_name: button_class, value: value)
  select_visible_elements elements
end

#find(value) ⇒ Element

Find the first element containing value

Parameters:

  • value (String)

    the value to search for

Returns:



22
23
24
# File 'lib/appium_lib/ios/xcuitest/element/generic.rb', line 22

def find(value)
  raise_error_if_no_element finds(value).first
end

#find_exact(value) ⇒ Element

Find the first element exactly matching value

Parameters:

  • value (String)

    the value to search for

Returns:



37
38
39
# File 'lib/appium_lib/ios/xcuitest/element/generic.rb', line 37

def find_exact(value)
  raise_error_if_no_element finds_exact(value).first
end

#finds(value) ⇒ Array<Element>

Find all elements containing value

Parameters:

  • value (String)

    the value to search for

Returns:



29
30
31
32
# File 'lib/appium_lib/ios/xcuitest/element/generic.rb', line 29

def finds(value)
  elements = find_eles_by_predicate_include value: value
  select_visible_elements elements
end

#finds_exact(value) ⇒ Array<Element>

Find all elements exactly matching value

Parameters:

  • value (String)

    the value to search for

Returns:



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

def finds_exact(value)
  elements = find_eles_by_predicate value: value
  select_visible_elements elements
end

#first_buttonUIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

Find the first UIAButton|XCUIElementTypeButton.



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

def first_button
  first_ele button_class
end

#first_textUIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT

Find the first UIAStaticText|XCUIElementTypeStaticText.



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

def first_text
  first_ele static_text_class
end

#first_textfieldTextField

Find the first TextField.

Returns:

  • (TextField)


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

def first_textfield
  _textfield_with_predicate
end

#last_buttonUIA_BUTTON|XCUIELEMENT_TYPE_BUTTON

TODO: add documentation regarding previous element.

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

Find the last UIAButton|XCUIElementTypeButton.



59
60
61
# File 'lib/appium_lib/ios/xcuitest/element/button.rb', line 59

def last_button
  last_ele button_class
end

#last_textUIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT

Find the last UIAStaticText|XCUIElementTypeStaticText.



56
57
58
# File 'lib/appium_lib/ios/xcuitest/element/text.rb', line 56

def last_text
  last_ele static_text_class
end

#last_textfieldTextField

Find the last TextField.

Returns:

  • (TextField)


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

def last_textfield
  result = _textfields_with_predicate.last
  raise _no_such_element if result.nil?

  result
end

#secure_text_field_classString

Returns Class name for secure text field.

Returns:

  • (String)

    Class name for secure text field



28
29
30
# File 'lib/appium_lib/ios/xcuitest/element/textfield.rb', line 28

def secure_text_field_class
  ::Appium::Ios::XCUIELEMENT_TYPE_SECURE_TEXT_FIELD
end

#static_text_classString

Returns Class name for text.

Returns:

  • (String)

    Class name for text



23
24
25
# File 'lib/appium_lib/ios/xcuitest/element/text.rb', line 23

def static_text_class
  ::Appium::Ios::XCUIELEMENT_TYPE_STATIC_TEXT
end

#text(value) ⇒ UIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT

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:



31
32
33
34
35
# File 'lib/appium_lib/ios/xcuitest/element/text.rb', line 31

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

  raise_error_if_no_element texts(value).first
end

#text_exact(value) ⇒ UIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT

Find the first UIAStaticText|XCUIElementTypeStaticText that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



63
64
65
# File 'lib/appium_lib/ios/xcuitest/element/text.rb', line 63

def text_exact(value)
  raise_error_if_no_element texts_exact(value).first
end

#text_field_classString

Returns Class name for text field.

Returns:

  • (String)

    Class name for text field



23
24
25
# File 'lib/appium_lib/ios/xcuitest/element/textfield.rb', line 23

def text_field_class
  ::Appium::Ios::XCUIELEMENT_TYPE_TEXT_FIELD
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)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/appium_lib/ios/xcuitest/element/textfield.rb', line 37

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 = _textfields_with_predicate[index]
    raise _no_such_element if result.nil?

    return result

  end

  raise_error_if_no_element textfields(value).first
end

#textfield_exact(value) ⇒ TextField

Find the first TextField that exactly matches value.

Parameters:

  • value (String)

    the value to match exactly

Returns:

  • (TextField)


82
83
84
# File 'lib/appium_lib/ios/xcuitest/element/textfield.rb', line 82

def textfield_exact(value)
  raise_error_if_no_element textfields_exact(value).first
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>)


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

def textfields(value = false)
  return tags_include(class_names: [text_field_class, secure_text_field_class]) unless value

  elements = tags_include class_names: [text_field_class, secure_text_field_class], value: value
  select_visible_elements elements
end

#textfields_exact(value) ⇒ Array<TextField>

Find all TextFields that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:

  • (Array<TextField>)


89
90
91
92
# File 'lib/appium_lib/ios/xcuitest/element/textfield.rb', line 89

def textfields_exact(value)
  elements = tags_exact class_names: [text_field_class, secure_text_field_class], value: value
  select_visible_elements elements
end

#texts(value = false) ⇒ Array<UIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT>

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:



41
42
43
44
45
46
# File 'lib/appium_lib/ios/xcuitest/element/text.rb', line 41

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

  elements = find_eles_by_predicate_include(class_name: static_text_class, value: value)
  select_visible_elements elements
end

#texts_exact(value) ⇒ Array<UIA_STATIC_TEXT|XCUIELEMENT_TYPE_STATIC_TEXT>

Find all UIAStaticTexts|XCUIElementTypeStaticTexts that exactly match value.

Parameters:

  • value (String)

    the value to match exactly

Returns:



70
71
72
73
# File 'lib/appium_lib/ios/xcuitest/element/text.rb', line 70

def texts_exact(value)
  elements = find_eles_by_predicate(class_name: static_text_class, value: value)
  select_visible_elements elements
end