2017-12-23 17 views
1

要素までスクロールしようとしています。下にスクロールし、私は動作していないように見える下のコードで試してみて、誰も私に完全に下にスクロールするソリューションを与えます。スワイプとscrollTo機能は、最新のJavaクライアントのバージョンで減価償却されると 、完璧なコードが要素にスクロールするための私のTASKAndroid、javaクライアントv-5.0.4、appium v​​-1.7.1でappiumを使用して特定の要素にスクロールしたい

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

ネイティブ、ハイブリッド、またはwebappのいずれかを指定できますか? – barbudito

+0

私はネイティブアプリケーションのみを使用しています –

答えて

0

を解決するために私を助けるApp_Settingsなどのテキストを持って、あなたは以下の

を使用することができます
androidDriver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0))" + 
     ".scrollIntoView(new UiSelector().description(\"App_Settings\"));"); 
+0

こんにちはJC、私はappiumとjavaクライアントの最新バージョンを使用しています。このバージョンでは、findElementByAndroidUIAutomatorの使用は償却されます。親切にスクロールのための別の方法を与える –

関連する問題