uiautomator-当我验证每个列表项中的文本时,无法使ListView滚动.当我点击屏幕上的最后一个项目时,它只会失败 [英] uiautomator - cannot get ListView to scroll as I validate text in each list item. it just fails when I hit the last item on screen

查看:205
本文介绍了uiautomator-当我验证每个列表项中的文本时,无法使ListView滚动.当我点击屏幕上的最后一个项目时,它只会失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证ListView中每个列表项中的文本,然后向下滚动一个,以便可以验证每个......但是由于某种原因,我无法让它继续滚动列表以验证每个元素.有没有人能使这种动作自动化,这是我能找到的最接近的. 如果这还不够,请告诉我:

I am trying to validate text in each list item in my ListView and scroll down one by one so I can validate each one... but for some reason I cant get it to continue scrolling through the list validating each element. Has anyone had any luck automating this kind of action.Here is the closest I can come to. Please let me know if this isn't enough info:

     UiScrollable scrollableList = new UiScrollable(new UiSelector()
        .resourceId("com.example.app:id/listView")
                .className(android.widget.ListView.class.getName())
                .index(3));

for ( i = 0; i < 100; i++ ) {
    UiObject listItem = scrollableList.getChildByText(new UiSelector()
        .className("android.widget.RelativeLayout")
        .instance(i), "Text Title");

    UiObject textBody = listItem.getFromParent(new UiSelector()
        .resourceId("com.example.app:id/textBody"));

    System.out.println("Validating: " + textBody.getText());

当时屏幕上只有5个listItems可见,因此当尝试达到第6个数字时它失败了,因为以下原因,它无法显示:

There are only 5 listItems visible on the screen at the time, so it fails when it tries to get to number 6, which it cant because:

a..它将不会尝试向前滚动以获取列表中的下一个
b.,即使它确实向前滚动以获取列表中的下一个,实例值也会减少到5,而不是增加到6.

a. it wont try to scroll forward to get the next one in the list
b. even if it did scroll forward to get the next one in the list, the instance value will decrease to 5, instead of increasing to 6.

我尝试了不使用.instance()方法的情况,但是在那种情况下,它只是一遍又一遍地遍历列表中的第一项,而不会进行到项2,3,4等.

I have tried it without the .instance() method, but in that case it just loops over the first item in the list over and over without progressing to item 2,3,4 ect.

如果有人遇到过这个问题,我希望能提供反馈.

If anyone has come across this issue, I would love feedback.

推荐答案

就我而言,我只想从该页面获取所有值. Android的局限性是,您只能使用屏幕上当前可见的对象. 查看此链接,了解Ui Automator在移动自动化方面的局限性- http://www.automationtestinghub.com/more-about-ui-automator-viewer/ 另外,我也尝试过此示例- http://www.qaautomated.com/2016/02/how-to-scroll-in-appium.html .我也尝试了此解决方案,但对我没有用,但是您可以尝试-- http://www.automationtestinghub.com/uiselector-android/. 我使用下面的代码行来解决我的问题.

In my case, I just want to get all values from that page. It is the limitation of Android that you can only work with the objects that are currently visible on the screen. Check out this link for Ui Automator with limitations with Mobile Automation - http://www.automationtestinghub.com/more-about-ui-automator-viewer/ Also, I have tried this example also -http://www.qaautomated.com/2016/02/how-to-scroll-in-appium.html. I have also tried this solution but it was not useful for me but you can try this -http://www.automationtestinghub.com/uiselector-android/. I have used below lines of code which solves my problem.

// to print value of visible objects on screen.
List<MobileElement> allTitleElements = ((AndroidDriver<MobileElement>)driver).findElementsByAndroidUIAutomator("new UiSelector().resourceId(\"com.experient.swap:id/editText\")");
System.out.println("Element Count - " + allTitleElements.size());

for(MobileElement element : allTitleElements)
 {
    System.out.println("Text - " + element.getText());
 }
// to click on last element of screen(country in my case) to scroll down page to last object
MobileElement abc = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                  +"new UiSelector().text(\"Country\"));"));
          abc.click();

这篇关于uiautomator-当我验证每个列表项中的文本时,无法使ListView滚动.当我点击屏幕上的最后一个项目时,它只会失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆