我正在尝试向下滚动到一个元素,在任何地方查找和搜索,没有代码帮助向下滚动,我尝试使用下面的代码似乎无法正常工作,任何人都给了我完美向下滚动的解决方案。 由于swipe和scrollTo函数在最新的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();
}
}
答案 0 :(得分:0)
对于滚动到元素的文本为App_Settings,可以使用下面的
androidDriver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0))" +
".scrollIntoView(new UiSelector().description(\"App_Settings\"));");