Ruby + Appium - 此会话不支持定位策略'名称'

时间:2017-05-02 19:22:03

标签: ruby session appium

C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': Locator Strategy 'name' is not supported for this session (Selenium::WebDriver::Error::InvalidSelectorError)
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/http/default.rb:107:in `request'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/bridge.rb:678:in `raw_execute'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/bridge.rb:656:in `execute'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/bridge.rb:625:in `find_element_by'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/appium_lib-9.4.3/lib/appium_lib/device/device.rb:440:in `find_element'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/appium_lib-9.4.3/lib/appium_lib/driver.rb:739:in `find_element'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/appium_lib-9.4.3/lib/appium_lib/driver.rb:242:in `rescue in block (4 levels) in promote_appium_methods'
        from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/appium_lib-9.4.3/lib/appium_lib/driver.rb:233:in `block (4 levels) in promote_appium_methods'
        from tindermation.rb:46:in `like_button'
        from tindermation.rb:75:in `<main>'
Looking for girls to match...

显然在Appium中已弃用name?有什么选择? Android Developer Options中是否有一些设置会返回特定UI元素的xpath,id,类名,可访问性ID等?

或者,我正在使用“开发者选项”单击某个坐标处的UI元素。例如:

def login_button
  sleep 1
  driver.execute_script 'mobile: tap', :x => 539, :y => 1464, :fingers => 1, :tapCount => 1, :duration => 0.5
  sleep 1
  driver.execute_script 'mobile: tap', :x => 871, :y => 1130, :fingers => 1, :tapCount => 1, :duration => 0.5
  sleep 1
end

但我得到了这个例外:

C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-3.4.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': Method has not yet been implemented (Selenium::WebDriver::Error::UnknownError)

为什么我无法点按登录按钮?

2 个答案:

答案 0 :(得分:1)

您可以使用"Appium Inspector",内置工具与Appium GUI应用程序或Android SDK工具"uiautomatorviewer"来查找应用程序的UI组件的不同属性。

答案 1 :(得分:1)

目前您需要使用xpath或id 或者,如果您有名称,则可以使用xpath作为
//*[@name='yourName']

driver.find_element(xpath: "//*[@name='yourName']").click

希望它有所帮助!!!