[英]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.