溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

UIAutomator中滾動(dòng)ListView獲得目標(biāo)TextView控件對(duì)象的經(jīng)驗(yàn)點(diǎn)滴

發(fā)布時(shí)間:2020-07-01 16:47:33 來源:網(wǎng)絡(luò) 閱讀:549 作者:zhukev 欄目:移動(dòng)開發(fā)

當(dāng)創(chuàng)建一個(gè)UiScrollable對(duì)象時(shí),如果指定的參數(shù)是new UiSelector().scrollable(true),那么會(huì)出現(xiàn)以下問題

  • 當(dāng)可滾動(dòng)控件(比如ListView)不滿一頁不需要滾動(dòng)時(shí),創(chuàng)建的UiSrollable對(duì)象返回值是為空的。
所以以下代碼是錯(cuò)誤的:
//Find out the new added note entry      UiScrollable noteList = new UiScrollable( new UiSelector().scrollable(true));  //would be null if the scrollable widget's not more than one page      UiObject note = null;
     note = noteList.getChildByText(new UiSelector().className("android.widget.TextView"), "Note1", true);  
<pre name="code" class="java">     assertThat(note,notNullValue());
note.longClick();
  
我們可以做一個(gè)增強(qiáng),當(dāng)判斷返回的UiScrollable對(duì)象是空的時(shí)候,我們直接去當(dāng)前頁面查找目標(biāo)控件:
//Find out the new added note entry      UiScrollable noteList = new UiScrollable( new UiSelector().scrollable(true));       UiObject note = null;
     if(noteList.exists()) {      	note = noteList.getChildByText(new UiSelector().className("android.widget.TextView"), "Note1", true);        }      else {      	note = new UiObject(new UiSelector().text("Note1"));      }      assertThat(note,notNullValue());            note.longClick();
另外一個(gè)個(gè)人認(rèn)為更好的解決辦法是,不要以“UiSelector().scrollable(true)”來初始化UiScrollable對(duì)象,而是明確的指定className為“android.widget.ListView"來初始化UiScrollable對(duì)象。實(shí)踐證明這樣子做的話就算ListView的內(nèi)容很少不需要翻頁時(shí),也能夠找到指定的當(dāng)前頁面的目標(biāo)控件。
//Find out the new added note entry      UiScrollable noteList = new UiScrollable( new UiSelector().className("android.widget.ListView"));        UiObject note = null;            note = noteList.getChildByText(new UiSelector().className("android.widget.TextView"), "Note1", true);        assertThat(note,notNullValue());            note.longClick();


 

作者

自主博客

微信

CSDN

天地會(huì)珠海分舵

http://techgogogo.com


服務(wù)號(hào):TechGoGoGo

掃描碼:

UIAutomator中滾動(dòng)ListView獲得目標(biāo)TextView控件對(duì)象的經(jīng)驗(yàn)點(diǎn)滴

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI

<sub id="o8dl5"></sub>

    1. <td id="o8dl5"></td>