Appium automation test: How to get element or text from custom UI in android [android.view.View]

别来无恙 提交于 2020-01-05 09:26:49

问题


I beginner test automation on Android by Appium. I use IUAtomatorviewer to get eLement from Android Application But i think my applicatoin is from customs UI. i see that is android.support.v7.widget.RecyclerView / android.view.View in [android.view.View] element, there no text or other informatoin

i see it include TextView, Image... same a item in listview

Here is my code

AndroidElement el = driver.findElement(By.id(io.***.vodi:id/message_list_item_chat_id));
AndroidElement el2 = (AndroidElement) el.findElementByClassName("android.view.View");
el2.getText(); //result is blank
el2.getAttribute("text") //result is blank

so how do i get text inner [android.view.View] ? or attribute of View

Here image of UIAutomatorviewer


回答1:


Get the "recycler view" by its resource-id. You can then get the different view's inside and select the 4th one to view "view #4".




回答2:


I was also facing the same issue in getting text from android view. below code helpful for me:

Get all your element in a list :

List<WebElement> allChats : driver.findElements(By.xpath("//*[@class='android.view.View']"));

Then iterate through for loop and get the text using name attribute

for(WebElement chat : allChats)
{
     System.out.println(chat.getAttribute("name"));
}


来源:https://stackoverflow.com/questions/36497486/appium-automation-test-how-to-get-element-or-text-from-custom-ui-in-android-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!