2017-04-12 57 views
-1

image如何appium使用Java

點擊元素中的GridView我有線性佈局的列表。 我想點擊一個應用程序,我可以在頁面上滾動,但無法點擊應用程序。

我沒有得到任何方式從GridView控件內單擊項目。

任何機構可以幫助我解決我的問題呢?

+0

首先讓我們看看你的努力。 – Chirag

回答

0

例如電網,如果我有我的網格20個項目,但我的屏幕能夠顯示只有10根據我的屏幕尺寸,然後在UI的Automator項目也只得到那些可以在屏幕上。當我再滾動剩餘的元素將在UI的Automator

可見,你甚至可以在網格視圖中單擊應用程序。滾動後,必須重新加載驅動程序的內容,因爲當你再滾動新項目將顯示那些不會提供在以前的驅動程序內容

WebDriver wd = driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 
boolean flag = false; 
WebElement firstItem = null; 
do { 
    List<WebElement> allApps = wd.findElements(By.xpath("//android.widget.ListView")); 

    if (firstItem.getText().equals(allApps.get(0).getText())) { 
     System.out.println("Reached to end of list"); 
     break; 
    } 

    for (WebElement webElement : allApps) { 
     if (webElement.getText().contains("Your App Name")) { 
      webElement.click(); 
      flag = true; 
      break; 
     } 
    } 
    firstItem = allApps.get(0); 

    if (!flag) { 
     horizontalScroll(); 
    } 
} while (!flag); 

試試這個,讓我知道,如果你面對任何問題

+0

謝謝。但我仍然可以點擊元素。錯誤將會失敗定位元素。 – shilpa

+0

嘗試調試並查看到底發生了什麼。你是否正在調試所有App?如果您正在獲取所有應用程序,然後檢查是否將文本與確切的應用程序進行比較for for循環中的名稱 – Karthikeya

+0

添加System.out.println(webElement.getText());並查看它是否打印所有應用程序名稱 – Karthikeya

0

請找到與它相匹配的圖像來尋找分層。 (0)的FrameLayout(0)的LinearLayout(0)的FrameLayout(0)的LinearLayout的ViewGroup(1)android.support.v4.widget.DrawerLayout的FrameLayout RelativeLayout的GridView的(0)的FrameLayout(1)的LinearLayout(0)的LinearLayout

Hierarchi of gridview

hierarchi of webelement