问题:在使用 appium 运行 contactmanager 的 ruby 脚本时,无法使用 tag_name 进行元素定位.
环境:
Window7_64bit 系统,安装了以下最新的 appium gem 包
*** LOCAL GEMS ***
appium_console (1.0.3)
appium_lib (6.0.0)
运行成功的代码 (使用 name,id 定位):
# encoding: utf-8
require 'rubygems'
require 'appium_lib'
describe 'ContactForAppium' do
APP_PATH = 'D:/Appium_Script/apps/ContactManager.apk'
def desired_caps
{
caps: {
app: APP_PATH,
appActivity: '.ContactManager',
appPackage: 'com.example.android.contactmanager',
platformName: 'android',
platformVersion: '4.4.2',#API:19
deviceName: 'emulator-5554',
},
appium_lib: {
sauce_username: nil,
sauce_access_key: nil,
debug: true,
wait: 60
}
}
end
before do
@driver = Appium::Driver.new(desired_caps).start_driver
end
after do
@driver.quit
end
it 'Contact' do
el = @driver.find_element(:name, 'Add Contact')
puts el.text
el.click
id = @driver.find_element(:id, "com.example.android.contactmanager:id/contactNameEditText")
id.send_keys("My name")
phone = @driver.find_element(:id, "com.example.android.contactmanager:id/contactPhoneEditText")
phone.send_keys("13800000001")
email = @driver.find_element(:id, "com.example.android.contactmanager:id/contactEmailEditText")
email.send_keys("someone@somewhere.com")
@driver.find_element(:name, "Save").click
end
end
运行失败的代码 (使用 tag_name 定位):
# encoding: utf-8
require 'rubygems'
require 'appium_lib'
describe 'ContactForAppium' do
APP_PATH = 'D:/Appium_Script/apps/ContactManager.apk'
def desired_caps
{
caps: {
app: APP_PATH,
appActivity: '.ContactManager',
appPackage: 'com.example.android.contactmanager',
platformName: 'android',
platformVersion: '4.4.2',#API:19
deviceName: 'emulator-5554',
},
appium_lib: {
sauce_username: nil,
sauce_access_key: nil,
debug: true,
wait: 60
}
}
end
before do
@driver = Appium::Driver.new(desired_caps).start_driver
end
after do
@driver.quit
end
it 'Contact' do
name = @driver.find_element(:name, 'Add Contact')
puts name.text
name.click
tag_name = @driver.find_elements(:tag_name, "textfield")
tag_name.send_keys("My name")
end
end
报错 log:
d:\Appium_Script\spec>rspec -f doc ContactForAppium2_fail.rb
ContactForAppium
Add Contact
Contact (FAILED - 1)
Failures:
1) ContactForAppium Contact
Failure/Error: tag_name = @driver.find_elements(:tag_name, 'textfield')
Selenium::WebDriver::Error::UnknownCommandError:
Invalid locator strategy: tag name
# ./ContactForAppium2_fail.rb:38:in `block (2 levels) in <top (required)>'
Finished in 31.73 seconds (files took 0.64104 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./ContactForAppium2_fail.rb:34 # ContactForAppium Contact