我想知道如何使用appium和java向下滚动以单击Android中的元素?
我在"android.support.v7.widget.RecyclerView
“中有一个元素列表。由于它有超过10个元素,我们需要滑动屏幕才能看到下面的元素。每个元素都有相同的id,即"com.osanda.exampleapp/textViewTitle
“。但是他们的文本是不同的,就像“苹果”,“橙子”,“葡萄”......
我只需要滚动并点击相关元素的文本(“Apple”,"Orange","Grapes".....)
我遵循了很多教程,但都做不好。我已经设法向下滚动屏幕了。但当元素位于滚动的中间位置时,它将不起作用。
当我列出元素名称时,它只显示可见元素,而不是所有元素。
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());
}
谢谢。
发布于 2017-10-16 17:27:37
我尝试了这个解决方案,它对我很有效。
public void scrollAndClick(String visibleText) {
androidDriver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+visibleText+"\").instance(0))").click();
}
}
发布于 2020-01-10 20:03:09
在Appium的新版本中,您可以使用以下内容:
TouchActions action = new TouchActions(driver);
action.scroll(element, 10, 100);
action.perform();
element.click();
发布于 2017-10-06 23:06:15
请使用下面的代码。它将滚动,直到文本可见。
String uiSelector = "new UiSelector().textMatches(\"" + text
+ "\")";
String command = "new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView("
+ uiSelector + ");";
driver.findElementByAndroidUIAutomator(command);
现在,您可以在此之后执行单击操作。
https://stackoverflow.com/questions/46550497
复制相似问题