通過xpath查找android app控件的幾個寫法


1、使用包含關系定位元素:

self.dr.find_element_by_xpath("//android.widget.TextView[contains(@text,'地鐵')]")
self.d.get_ui_by_xpath("//*[@class='android.widget.Button' and contains(@text,'允許')]").click()

2、使用屬性值定位元素:

self.dr.find_element_by_xpath("//android.widget.TextView[@text='地鐵']")

3、打兄弟元素,特別小心uiautomator上面顯示的是0、1、2、3算,但實際xpath是從1開始算的

self.driver.find_element_by_xpath('//*[@text="閃兌"]/../../../android.view.View[4]/android.view.View[4]').text

4、使用下標,說明是第幾個元素:

self.dr.find_element_by_xpath("//android.widget.LinearLayout/android.widget.RelativeLayout[1]")

5、使用語法查找兄弟節點(following-sibling是選取當前節點之后的所有節點;preceding-sibling是選擇當前節點之前的所有節點):

self.dr.find_element_by_xpath('((//*[@text="com.test.demo"])/following-sibling::TextView)[2]')           # 查找到text為com.test.demo元素后面類型為textview的第二個兄弟節點


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM