Skip to content

Commit dd82100

Browse files
Fix find_eles_attr
Fix #18
1 parent de7a1bc commit dd82100

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

lib/appium_lib/helper.rb

+42-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,49 @@ def find_eles_attr tag_name, attribute
7979
$driver.execute_script js
8080
end if $os == :ios
8181

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+
82107
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
85125
end if $os == :android
86126

87127
# iOS only. Android uses uiautomator instead of uiautomation.

0 commit comments

Comments
 (0)