Appium:三:APP元素定位
APP控件定位
Xpath定位
- test属性定位:
 - driver.find_element(By.XPATH,'//*[@test="test属性"]').click()
 
- resource-id属性定位:
 - driver.find_element(By.XPATH,‘//*[@resource-id="属性"]'.click()
 
- class属性定位:
 - driver.find_element(By.XPATH,‘//*[@class="属性"]'.click()
 
Xpath高级定位
- Xpath模糊定位技巧
 - driver.find_element(By,XPATH,'//*[contains(@text,"属性")]').click()
 
- Xpath组合定位技巧
 - driver.find_element(By,XPATH,'//*[@text="属性" adn @resource-id="属性"]').click()
 
- Xpath层级定位
 - driver.find_element(By,XPATH,'//*[@text="属性"]/..')
 
UiAutomator 定位:
- text文本定位
 - self.driver.find_element_by_android_uiautomator('new UiSelector().text("xx")').click
 - new UiSelector().textContains("股票").click()
 - new UiSelector().textStartsWith("股").click()
 
- resourceid定位
 - new UiSelector().resourceid("xx")
 
- class定位
 - new UiSelector().className("xx“)[2]
 
- contenet-desc定位
 - new UiSelector().description("xx“)
 
- 组合定位
 - new UiSelector().description("xx").text("文本属性")
 

- 滚动查找元素
 - self.driver.find_element_by_android_uiautomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollintoView(new UiSelector().text("text属性").instance(0));').click()
 
| /a/x[1] | 选取a子元素的第一个x元素 | 
| /a/x[last()] | 选取a子元素的最后一个x元素 | 
| /a/x[last()-1] | 选取a子元素的倒数第2个x元素 | 
| /a/x[position()<3] | 选取最前面的两个属于a元素的子元素的x元素 | 
| /a/x[price>30.00] | 选取a元素的所有x元素,且其中price元素值大于30.00 | 
| /a/x[price>30.00]/title | 选取a元素的所有x元素的title元素,且其中price元素大于30.00的 | 
| //title[@name='joke'] | 选取所有的title元素,且这些元素值有name的joke属性 | 
| / | 从根节点选取 | 
| // | 从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置 | 
| . | 选取当前节点 | 
| .. | 选取当前节点的父节点 | 
| @ | 选取属性 | 
                    
                
                
            
        
浙公网安备 33010602011771号