简体   繁体   English

如何使用Java Appium Client在Android中滚动?

[英]How to scroll in android using java appium client?

I am trying to automate a native android app using Appium. 我正在尝试使用Appium自动执行本机android应用程序。 I am using the java client for the same. 我使用相同的Java客户端。 Below are the dependencies that I have included. 以下是我包含的依赖项。 Since I am using version 7 of the java client, there's no support for scroll and swipe method. 由于我正在使用Java客户端的版本7,因此不支持滚动和滑动方法。 SO alternatively how do I scroll to a particular element?? 所以或者我如何滚动到一个特定的元素? I have come across some code snippets using TouchAction class, but I just want to know if there's any alternative solution apart from the TouchAction class?? 我使用TouchAction类遇到了一些代码片段,但我只想知道TouchAction类之外是否还有其他解决方案? Maven dependency - Maven依赖-

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>

您可以将findElementByAndroidUIAutomator与不同的条件(例如文本,说明)一起使用:

((AndroidDriver<?>) appiumDriver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+ text + "\").instance(0))");
public MobileElement scrollElementByTextUsingDescription(String scrollableListContDesc, String uiClassSelector, String text) {
        return driver.findElement(MobileBy.AndroidUIAutomator(
           "new UiScrollable(new UiSelector().description(\"" + scrollableList + "\"))" +
           ".getChildByText(new UiSelector().className(\"" + uiClassSelector + "\"), \"" + text + "\")"));
    }

scrollableListContDesc is automationId/cont-Description of scrollable list scrollableListContDesc是automationId / cont-可滚动列表的描述

uiClassSelector is the class name of scrollable list eg android.view.View uiClassSelector是可滚动列表的类名称,例如android.view.View

text is the text of the element upto where you want to scroll. text是要滚动到的元素的文本。

If you don't have cont-description in scrollable list, you can use following method: 如果滚动列表中没有cont-description ,则可以使用以下方法:

public MobileElement scrollElementByTextUsingId(String scrollableListId, String uiClassSelector, String text) {
            return driver.findElement(MobileBy.AndroidUIAutomator(
               "new UiScrollable(new UiSelector().resourceId(\"" + scrollableListId + "\"))" +
               ".getChildByText(new UiSelector().className(\"" + uiClassSelector + "\"), \"" + text + "\")"));
        }

scrollableListId is id/resourceId of scrollable list scrollableListId是可滚动列表的id / resourceId

UIScrollable/UISelector is one alternative to TouchActions that you can use to scroll/swipe. UIScrollable / UISelector是TouchAction的一种替代方法,可用于滚动/滑动。 Example: 例:

MobileElement element = driver.findElement(MobileBy.AndroidUIAutomator(
            "new UiScrollable(new UiSelector().resourceId(\"com.android.vending:id/data_view\")).scrollIntoView("
            + "new UiSelector().textContains(\"HelloWorld\").instance(2))"));

This blog post covers a variety of solutions to swipe/scroll well. 这篇博客文章涵盖了多种解决方案,可以很好地滑动/滚动。

暂无
暂无

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

相关问题 无法使用Java客户端使用Appium滚动Android应用程序 - Unable to scroll Android app with Appium using Java Client 无法使用Java Client 7.0滚动使用Appium的Android Native App - Unable to scroll android native app with appium using java client 7.0 如何使用appium和java向下滚动点击Android中的元素? - How to scroll down to click the element in Android using appium and java? 如何使用appium + Java在Android App中滚动? - How to scroll in the Android App using appium+Java? 如何使用Appium Java在android滚动视图中将Web元素名称添加到ArrayList中? - How to add web element names in android scroll view into an ArrayList using Appium Java? 在Appium中,如何使用Java方法在Android屏幕中提供如何滚动和验证所需的元素集? - In Appium, How to Scroll and validate the required set of elements are available in the Android screen using a Java method? 页面滚动没有发生appium java客户端 - page scroll is not happening appium java client 如何使用 appium java 客户端 6.1.0 自动化 Android 手机底部的 Home、back、up、down、Menu 按钮? - How to automate Home,back,up,down,Menu button at bottom of Android phone using appium java client 6.1.0? 如何使用Java在Appium中垂直滚动混合应用程序 - How to scroll vertically in appium for hybrid app using java 如何使用Java滚动到最新版本的Appium中的特定元素? - How to scroll to specific element inLatest version of Appium using Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM