层级定位
- 父节点定位子节点
- 子节点定位父节点
- 子节点定位兄弟节点
- 爷爷节点定位孙子节点
"//*[@text='09988']/../../..//*[@resource-id='com.xueqiu.android:id/current_price']"
uiautomator定位
self.driver.find_element_by_android_uiautomator('new UiSelector().text("我的")').click()
self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/tab_name").text("我的")')
self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("帐号密码")').click()
self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/login_account")').send_keys('15899851533')
self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("登录密码")').send_keys('abc942493')
self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("登录")').click()
# 通过父节点,找子节点
self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.xueqiu.android:id/title_container").childSelector(text("股票"))')
# 兄弟节点
self.driver.find_element_by_android_uiautomator(
'new UiSelector().resourceId("com.xueqiu.android:id/title_container").fromParent(text("股票"))')
- uiautomator 滚动查找
self.driver.find_element_by_android_uiautomator(
'new UiScrollable(new UiSelector().scrollable(true).instance(0)).'
'scrollIntoView(new UiSelector().text("乱世佳韭").instance(0));').click()