我想知道如何向下滚动以使用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 Swipedown() throws InterruptedException
{
// Select till which position you want to move the seekbar
TouchAction action=new TouchAction((PerformsTouchActions) driver);
Dimension dimensions = driver.manage().window().getSize();
action.press(446,1404).moveTo(554,1500).release().perform();
System.out.println("swipe down to set seekbar successfully");
Thread.sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)
你们能帮我看看我在这里做错了什么。
任何帮助将不胜感激。
我在向下滚动到iOS和Android应用程序中的某个元素时遇到麻烦。由于从Appium 1.6.3更新到1.7.1,将io.appium更新到6.1.0,因此不建议使用swipe方法,唯一的解决方案是使用TouchActions。
我尝试使用TouchActions解决它,但是它根本没有滚动,或者滚动方向错误。
到目前为止,我的解决方案看起来像这样,也许有人可以解释我做错了什么:
public void scrollDownUntilElementVisible(WebElement element){
TouchAction touchAction = new TouchAction(getDriver());
for(int i=0; i<dimensions.getHeight();i++){
if(element.isDisplayed()){
break;
}else{
touchAction.press(0,0).moveTo(element).release().perform();
}
}
}
Run Code Online (Sandbox Code Playgroud)
它不是完整的代码,但是希望您能理解。
如果我使用x,y坐标代替我在示例中查找的webElement,它将如何工作?它不能像以前版本中的“滑动”方法那样工作,或者我做得不好。也许有人可以解释。