Objective
appium1.5 the following old version can be located by name, the new version from 1.5 does not support name positioning
Name Location Error
1. The latest version of Appium V1.7 with name, error:
Selenium.common.exceptions.InvalidSelectorException:Message:Locator strategy ' name ' is not supported for this session
2. This error means that the "name" method is currently unsupported because Appium has abandoned the location method of name since the 1.5 version.
XPath positioning
1. Since the name positioning is abandoned, it means that there is a more advanced positioning instead of it, in fact, the XPath location contains the name of the positioning method.
2. Usually used selenium, when positioning the text on the page, you should know this XPath syntax:
//*[text()='页面text文本']
The XPath syntax inside the appium is a little different from the selenium:
//*[@text='页面text文本']
Text Property
1. The above XPath syntax is appropriate for this text property on the page, so it's only right to navigate directly to it, so the question is: What if there are multiple text properties on the page?
2.xpath syntax inside * is to match any value, in Selenium * is to match any tag, Appium * is to match any class name, if a few text class attribute is different, you can use the following combination:
//android.widget.TextView[@text='小说']
Reference Code
# coding:utf-8from appium import webdriverfrom time import sleepdesired_caps = { 'platformName': 'Android', 'deviceName': '127.0.0.1:62001', 'platformVersion': '4.4.2', 'appPackage': 'com.baidu.yuedu', 'appActivity': 'com.baidu.yuedu.splash.SplashActivity' }driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)# 获取当前界面activityac = driver.current_activityprint(ac)# 等主页面activity出现driver.wait_activity(".base.ui.MainActivity", 10)# 点'知道了'driver.find_element_by_id("com.baidu.yuedu:id/positive").click()sleep(2)# 定位页面上text属性# driver.find_element_by_name("小说").click() # V1.5以后版本不支持name定位了driver.find_element_by_xpath("//*[@text='小说']").click()
Appium+python Automated 28-name Positioning