Osa*_*han 4 java automation android scroll appium
我想知道如何向下滚动以使用appium和java单击Android中的元素?
我在" android.support.v7.widget.RecyclerView"中有一个元素列表.由于它有10个以上的元素,我们需要滑动屏幕才能看到下面的元素.每个元素都具有相同的id,即" com.osanda.exampleapp/textViewTitle".但他们的文字不同,如"Apple","Orange","Grapes"......
我只需要滚动并使用其文本("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());
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
这对我有用.
public void scrollAndClick(String visibleText) {
androidDriver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+visibleText+"\").instance(0))").click();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16093 次 |
| 最近记录: |