-
絕對定位:根據嚴格的父子關係定位
-
相對定位:根據條件匹配定位
-
慢的原因:XPath 定位比其他定位慢,因爲需要遞歸解析每個元素的屬性
-
慢的不明顯的原因:有 Cache 機制
絕對定位
driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/android.widget.RelativeLayout[1]/android.widget.TextView")
相對定位
-
查找
- //*[@text=‘登錄’]
- //*[contains(@resource-id,‘login’)]
-
條件匹配
- //*[contains(@resource-id,‘login’) and contains(@text,‘登錄’)]
- //*[contains(@text,‘登錄’) or contains(@label,‘登錄’)]
-
尋找所有元素 //*