如何使用appium和java向下滚动以单击Android中的元素? [英] How to scroll down to click the element in Android using appium and java?

查看:26
本文介绍了如何使用appium和java向下滚动以单击Android中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用 appium 和 java 在 Android 中向下滚动以单击元素?

I would like to know how to scroll down to click the element in Android using appium and java?

我在android.support.v7.widget.RecyclerView"中有一个元素列表.由于它有10多个元素,我们需要滑动屏幕才能看到下面的元素.每个元素都有相同的 id,即com.osanda.exampleapp/textViewTitle".但是他们的文字不同,如Apple"、Orange"、Grapes"……

I am having a list of elements inside "android.support.v7.widget.RecyclerView". Since it has more than 10 elements, we need to swipe the screen to see the below elements. Each element has same id which is "com.osanda.exampleapp/textViewTitle". But their texts are different like "Apple", "Orange", "Grapes"......

我只需要使用文本(Apple",Orange",Grapes".....)滚动并单击相关元素

All I need is to scroll and click the relevant element using its text("Apple", "Orange", "Grapes".....)

我已经学习了很多教程,但无法正确完成.我设法向下滚动屏幕.但是当元素在滚动的中间位置时它不会工作.

I have followed many tutorials but couldn't do it properly. I have managed to scroll down the screen. But it won't work when the element is in the middle position of the scroll.

当我列出元素名称时,它只显示可见元素,而不是所有元素.

When I listed the element names it only shows the visible elements, not all elements.

List<WebElement> elements = androidDriver.findElementByClassName("android.support.v7.widget.RecyclerView").findElements(By.id("com.osanda.exampleapp:id/textViewTitle"));
        for(WebElement element : elements) {
            System.out.println(element.getText());
        }

谢谢.

推荐答案

我尝试了这个解决方案,它对我有用.

I tried this solution and it is worked for me.

public void scrollAndClick(String visibleText) {
     androidDriver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+visibleText+"\").instance(0))").click();
        }
    }

这篇关于如何使用appium和java向下滚动以单击Android中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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