Appium——元素定位

來源:互聯網
上載者:User

標籤:frame   roi   會同   out   UI   簡單   android   package   按鈕   

首先介紹兩種定位元素的工具,appium內建的 Inspector 和 android SDK內建的 uiautomatorviewer1、UIAutomator Viewer比較簡單,在模擬器開啟app後,開啟它,選擇

 

點擊這個按鈕,就會同步模擬器或真機介面

 

點擊頁面中的元素,在右下角會顯示該元素的一些資訊

 

2、Inspector(android)使用inspector就比較麻煩了,先設定appium①首先是android setting

 

第一次設定的時候 package和launch activity是沒有選擇項的可以為空白,填入Application path②general settings中勾選下面這兩項

 

③啟動appium 就會發現會自動安裝apk,然後點擊appium中的搜尋按鈕,彈出inspector window,點擊refresh,重新整理出同步頁面,在右下角也會顯示出元素資訊

 

 如果出現錯誤,記得查看appium 日誌排查  元素定位方式: ①by_id 

 

②by_class_name  ③by_name如果要定位的控制項是有文字的,可以直接嘗試by_name,或者如果中的text後面是有值的話 也可以用by_name ④by_link_text如果是herf 連結標籤的 可以直接嘗試用link定位,但是只適用於webview,跟web自動化的是一致的 ⑤by_xpath如,定位活動按鈕

 

FrameLayout/ListView/LinearLayout/GridView/LinearLayout[1] 這是xpath的絕對路徑xpath可以這樣寫第一種,利用元素屬性//android.widget.TextView[contains(@text, ‘活動‘)]第二種,基本就是看元素路徑了,利用index//android.widget.ListView[0]/android.widget.LinearLayout[0]/android.widget.GridView/android.widget.LinearLayout[0]/android.widget.TextView一層層向下分析,如果出現相同class則根據index來定位,跟web中的xpath相同

Appium——元素定位

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.