Appium自动化测试:如何从android中的自定义UI获取元素或文本[android.view.View] [英] Appium automation test: How to get element or text from custom UI in android [android.view.View]
问题描述
我通过Appium在Android上进行了初学者的自动化测试. 我使用IUAtomatorviewer从Android应用程序获取eLement 但是我认为我的申请来自海关用户界面.我看到那是 android.support.v7.widget.RecyclerView/android.view.View 在[android.view.View]元素中, 没有文字或其他信息
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
我看到它包括TextView,Image ...与listview中的项目相同
i see it include TextView, Image... same a item in listview
这是我的代码
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
所以 如何获取内部[android.view.View]的文本?或View的属性
so how do i get text inner [android.view.View] ? or attribute of View
这里的UIAutomatorviewer图像
Here image of UIAutomatorviewer
推荐答案
在从android视图获取文本时,我也面临着同样的问题.下面的代码对我有用:
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']"));
然后遍历for循环并使用 name
属性
Then iterate through for loop and get the text using name
attribute
for(WebElement chat : allChats)
{
System.out.println(chat.getAttribute("name"));
}
这篇关于Appium自动化测试:如何从android中的自定义UI获取元素或文本[android.view.View]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!