我想使用Android中的appium、java客户端v-5.0.4和appium v-1.7.1向下滚动到特定元素

我想使用Android中的appium、java客户端v-5.0.4和appium v-1.7.1向下滚动到特定元素,appium,appium-android,Appium,Appium Android,我试图向下滚动到一个元素,到处查看和搜索,没有代码帮助向下滚动,我尝试了下面的代码,但似乎不起作用,任何人都给了我完美向下滚动的解决方案。 由于在最新的java客户机版本中,滑动和滚动功能被贬低,一个完美的代码将帮助我解决我的任务 package mobileapp.com.example; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.By; import org.

我试图向下滚动到一个元素,到处查看和搜索,没有代码帮助向下滚动,我尝试了下面的代码,但似乎不起作用,任何人都给了我完美向下滚动的解决方案。 由于在最新的java客户机版本中,滑动和滚动功能被贬低,一个完美的代码将帮助我解决我的任务

package mobileapp.com.example;

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AndroidFindBy;

public class Day5 {

    AndroidDriver<WebElement> driver;

    @AndroidFindBy (uiAutomator = "new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().textContains(\"PHP\"))")
    public WebElement scrollStepOne;

    @BeforeTest
    public void setup() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("BROWSER_NAME", "Android");
    capabilities.setCapability("VERSION", "6.0.1");
    capabilities.setCapability("deviceName","Nexus 5");
    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("appPackage", "com.vector.guru99");
    capabilities.setCapability("appActivity","com.vector.guru99.BaseActivity");

    driver= new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    }

    @Test
    public void StartTest() throws InterruptedException {

        //Verify Homepage
        if(driver.findElement(By.id("android:id/action_bar_title")).isDisplayed())
            System.out.println("Home page is displayed");
        else
            System.out.println("Home page is not displayed");

        //step2 - click on Course List tab

        driver.findElement(By.name("Course List")).click();
        System.out.println("Courses list are : ");
        Thread.sleep(3000);

        //Step 3 - darg until PHP course found and click on it
        scrollStepOne.click();
        Thread.sleep(3000);
//      driver.findElement(By.xpath("//android.widget.TextView[@text()='PHP']")).click();
//      Thread.sleep(3333);

        //Step 4 - Click on lesson 1 and verify
        driver.findElement(By.xpath("//android.widget.TextView[@text='What is PHP? Write your first PHP Program']")).click();
        Thread.sleep(3333);

        if(driver.findElement(By.id("com.vector.guru99:id/lesson_title")).isDisplayed())
            System.out.println("First Lesson is displayed");
        else
            System.out.println("First lesson not opened");


    }

    @AfterTest
    public void tearDown() {
        driver.quit();
    }

}
package mobileapp.com.example;
导入java.net.MalformedURLException;
导入java.net.URL;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.remote.DesiredCapabilities;
导入org.testng.annotations.postest;
导入org.testng.annotations.BeforeTest;
导入org.testng.annotations.Test;
导入io.appium.java_client.android.AndroidDriver;
导入io.appium.java_client.pagefactory.AndroidFindBy;
公共课第5天{
机器人驱动;
@AndroidFindBy(uiAutomator=“新建UiScrollable(新建UiSelector()).scrollIntoView(新建UiSelector().textContains(\“PHP\”)))
公共网页元素滚动第一步;
@试验前
public void setup()引发畸形的DurException{
DesiredCapabilities=新的DesiredCapabilities();
setCapability(“浏览器名称”、“安卓”);
能力。设置能力(“版本”,“6.0.1”);
能力。设置能力(“deviceName”、“Nexus 5”);
能力。设置能力(“平台名”、“安卓”);
setCapability(“appPackage”、“com.vector.guru99”);
capabilities.setCapability(“appActivity”、“com.vector.guru99.BaseActivity”);
驱动程序=新的AndroidDriver(新的URL(“http://127.0.0.1:4723/wd/hub(能力),;
}
@试验
public void StartTest()引发InterruptedException{
//验证主页
if(driver.findElement(By.id(“android:id/action\u bar\u title”)).isDisplayed())
System.out.println(“显示主页”);
其他的
System.out.println(“不显示主页”);
//步骤2-单击课程列表选项卡
driver.findElement(按.name(“课程列表”))。单击();
System.out.println(“课程列表为:”);
睡眠(3000);
//第3步-直到找到PHP课程并点击它
滚动第一步。单击();
睡眠(3000);
//findElement(By.xpath(“//android.widget.TextView[@text()='PHP']))。单击();
//睡眠(3333);
//第4步-单击第1课并验证
findElement(By.xpath(“//android.widget.TextView[@text='What is PHP?编写第一个PHP程序']))。单击();
睡眠(3333);
if(driver.findelelement(By.id(“com.vector.guru99:id/lesson_title”)).isDisplayed())
System.out.println(“显示第一课”);
其他的
System.out.println(“第一课未打开”);
}
@事后
公共无效拆卸(){
driver.quit();
}
}

要滚动到具有文本作为应用程序设置的元素,您可以使用下面的

 androidDriver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0))" +
        ".scrollIntoView(new UiSelector().description(\"App_Settings\"));");

您能指定它是本机应用、混合应用还是webapp吗?我只使用本机应用Hi JC,我使用的是最新版本的appium和java client,在这个版本中,findElementByAndroidUIAutomator的使用将被折旧。请给出另一种滚动方式