1
1
# encoding: utf-8
2
2
# UIAButton methods
3
3
4
- =begin
5
- Method Signatures:
6
-
7
- button( text, number = -1 )
8
- buttons( text = nil )
9
- button_include( text )
10
- buttons_include( text )
11
- first_button
12
- last_button
13
-
14
- Examples:
15
-
16
- button 'text' # 1st button exactly matching text
17
- button 'text', 2 # 2nd button exactly matching text
18
-
19
- buttons # text of all buttons.
20
- buttons 'text' # all buttons exactly matching text
21
-
22
- button_include 'text' # the first button that includes text
23
- buttons_include 'text' # all buttons that include text
24
-
25
- first_button # the first button
26
- last_button # the last button
27
- =end
28
-
29
4
# Find a button by text and optionally number.
30
5
# @param text [String, Integer] the text to exactly match. If int then the button at that index is returned.
31
6
# @param number [Integer] the occurance of the button matching text. Defaults to the first button.
32
7
# @return [Button] the button found with text and matching number
33
8
def button text , number = 0
9
+ # return button at index.
34
10
return ele_index :button , text if text . is_a? Numeric
35
11
36
- number >= 1 ? button_text_num ( text , number ) :
37
- button_text ( text )
12
+ number >= 1 ? button_num ( text , number ) :
13
+ find_ele_by_text_include ( :button , text )
38
14
end
39
15
40
16
# Get an array of button texts or button elements if text is provided.
41
17
# @param text [String] the text to exactly match
42
18
# @return [Array<String>, Array<Buttons>] either an array of button texts or an array of button elements if text is provided.
43
19
def buttons text = nil
44
- text == nil ? find_eles_attr ( :button , :text ) :
45
- find_ele_by_text ( :button , text )
46
- end
47
-
48
- # Get the first button that includes text.
49
- # @param text [String] the text that the element must include
50
- # @return [Button]
51
- def button_include text
52
- find_ele_by_text_include :button , text
53
- end
54
-
55
- # Get all buttons that include text.
56
- # @param text [String] the text that the element must include
57
- # @return [Array<Button>]
58
- def buttons_include text
59
- find_eles_by_text_include :button , text
20
+ text == nil ? find_eles_attr ( :button , :text ) :
21
+ find_eles_by_text_include ( :button , text )
60
22
end
61
23
62
24
# Get the first button element.
@@ -71,16 +33,28 @@ def last_button
71
33
last_ele :button
72
34
end
73
35
74
- # -- prefer above methods before using these.
75
- private
76
-
77
36
# Get the first button element that exactly matches text.
78
37
# @param text [String] the text to match exactly
79
38
# @return [Button]
80
- def button_text text
39
+ def button_exact text
81
40
find_ele_by_text :button , text
82
41
end
83
42
43
+ # Get all button elements that exactly match text.
44
+ # @param text [String] the text to match exactly
45
+ # @return [Array<Button>]
46
+ def buttons_exact text
47
+ find_eles_by_text :button , text
48
+ end
49
+
50
+ # Get an array of button elements.
51
+ # @return [Array<Button>]
52
+ def e_buttons
53
+ find_eles :button
54
+ end
55
+
56
+ # Expected to be called via button method.
57
+ #
84
58
# Get the button element exactly matching text and
85
59
# occurrence. number=2 means the 2nd occurrence.
86
60
#
@@ -92,24 +66,18 @@ def button_text text
92
66
# so if there's no button found at number then
93
67
# return the first button.
94
68
#
95
- # @param text [String] the text to match exactly
69
+ # @param text [String] the text to match
96
70
# @param number [Integer] the button occurance to return. 1 = first button
97
- # @return [Button] the button that exactly matches text and number
98
- def button_text_num text , number = 1
71
+ # @return [Button] the button that matches text and number
72
+ def button_num text , number = 1
99
73
raise "Number must be >= 1" if number <= 0
100
74
number = number - 1 # zero indexed
101
75
102
76
result = nil
103
77
104
- elements = find_eles_by_text :button , text
78
+ elements = buttons text
105
79
elements . size > number ? result = elements [ number ]
106
80
: result = elements . first
107
81
108
82
result
109
- end
110
-
111
- # Get an array of button elements.
112
- # @return [Array<Button>]
113
- def e_buttons
114
- find_eles :button
115
- end
83
+ end
0 commit comments