@@ -79,9 +79,49 @@ def find_eles_attr tag_name, attribute
79
79
$driver. execute_script js
80
80
end if $os == :ios
81
81
82
+ # Returns an array of android classes that match the tag name
83
+ def tag_name_to_android tag_name
84
+ tag_name = tag_name . to_s . downcase . strip
85
+
86
+ def prefix *tags
87
+ tags . map! { |tag | "android.widget.#{ tag } " }
88
+ end
89
+
90
+ # must match names in AndroidElementClassMap (Appium's Java server)
91
+ case tag_name
92
+ when 'button'
93
+ prefix 'Button' , 'ImageButton'
94
+ when 'text'
95
+ prefix 'TextView'
96
+ when 'list'
97
+ prefix 'ListView'
98
+ when 'frame'
99
+ prefix 'FrameLayout'
100
+ when 'linear'
101
+ prefix 'LinearLayout'
102
+ when 'textfield'
103
+ prefix 'EditText'
104
+ end # return result of case
105
+ end
106
+
82
107
def find_eles_attr tag_name , attribute
83
- # on android, assume the attr is name (which falls back to text).
84
- mobile :find , [ 'all' , [ [ 26 , "(?i).*#{ tag_name } .*" ] , [ 100 ] ] ]
108
+ =begin
109
+ sel1 = [ [4, 'android.widget.Button'], [100] ]
110
+ sel2 = [ [4, 'android.widget.ImageButton'], [100] ]
111
+
112
+ args = [ 'all', sel1, sel2 ]
113
+
114
+ mobile :find, args
115
+ =end
116
+ array = [ 'all' ]
117
+
118
+ tag_name_to_android ( tag_name ) . each do |name |
119
+ # on android, assume the attr is name (which falls back to text).
120
+ # sel.className(name).getStringAttribute("name")
121
+ array . push [ [ 4 , name ] , [ 100 ] ]
122
+ end
123
+
124
+ mobile :find , array
85
125
end if $os == :android
86
126
87
127
# iOS only. Android uses uiautomator instead of uiautomation.
0 commit comments