简体   繁体   English

转换列表 <WebElement> 到WebElement

[英]Converting List<WebElement> to WebElement

I am using Appium and I want to print names of the elements in the list. 我正在使用Appium,我想打印列表中的元素名称。 I am using following code 我正在使用以下代码

List<WebElement> list = getDriver().findElementsByXPath(getLocator(Locators.MY_ITEM));
    List<String> strings = new ArrayList<>();
    for (WebElement object : list) {
        String text = object.getText();
        logger.info(text);
        if (!text.isEmpty())
            strings.add(text);
    }

But I am getting text always as empty. 但我总是将text视为空白。 What is the suggested approach over here. 这里建议的方法是什么。 Note each element is of type UIACollectionCell in case of iOS and on Android //android.widget.TextView[@text='%s'] 注意,对于iOS和Android,每个元素都是UIACollectionCell类型UIACollectionCell //android.widget.TextView[@text='%s']

From what I understand, you should be getting the text from the text attribute, replace: 根据我的理解,你应该从text属性中获取text ,替换:

String text = object.getText();

with: 有:

String text = object.getAttribute("text");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM