0

appium を使用して完全な連絡先リストを印刷または読み取りたい (私の .apk が連絡先アプリケーションであり、A から Z までの完全な連絡先が表示され、スクロールすることですべての連絡先を表示できるとします)。

最初の画面に表示されている連絡先をカウント/印刷できます(つまり、一部の連絡先を表示する画面では、デフォルトで10件の連絡先が表示され、さらにスクロールする必要があります)、上記の解決策にたどり着き、しばらくの間動作しましたが、その後、エラーがスローされます。この問題を修正する方法を教えてください java.lang.IndexOutOfBoundsException: Index: 9, Size: 9

私のコードは `

AppiumDriver ドライバー = null; ArrayList 値 = 新しい ArrayList();

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Galaxy S4");
    cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.4");
    cap.setCapability(MobileCapabilityType.APP_PACKAGE, "com.brainworks.contacts");
    cap.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.brainworks.contacts.ui.Main");

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),cap);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    List<WebElement> allContactsOnfirstScreen = driver.findElements(By.xpath("//*[@resource-id='com.brainworks.contacts:id/txt_name']"));
    driver.context("NATIVE_APP");
    Dimension size = driver.manage().window().getSize();
    int StartY = (int)(size.height * 0.70);
    int EndY = (int)(size.height * 0.55);
    int StartX = size.width/2;

    for(int i =0;i<200;i++){
        System.out.println("Contacts are = " + allContactsOnfirstScreen.get(i).getAttribute("text"));
        String Values = allContactsOnfirstScreen.get(i).getAttribute("text");
        values.add(Values);
        System.out.println("Value is = " + values);
        String ext = Values;
        String [] a = ext.split(",");
        String [] b = a[a.length-1].split("//]");
        System.out.println("val = " + b[0]);
        driver.swipe(StartX, StartY, StartX, EndY , 1000);
    }`

私が試した2番目の方法

            AppiumDriver driver = null;

    // desired cap as above in the first try

    // same as above -but now what i am doing is i am printing the list in for loop
            // then do a swipe form last element to first element then again print the new list 
            // and this cycle keeps on running until i reach the end of the list or the parameter
            // in the if loop.

    int XOfFirstElement = allContactsOnfirstScreen.get(0).getLocation().getX();
    int YOfFirstElement =  allContactsOnfirstScreen.get(0).getLocation().getY();

    System.out.println("X for XOfFirstElement = " + XOfFirstElement);
    System.out.println("Y for YOfFirstElement = " + YOfFirstElement);

    int XOfLastElement = allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-1).getLocation().getX();
    int YOfLastElement =  allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-1).getLocation().getY();

    System.out.println("X for XOfLastElement = " + XOfLastElement);
    System.out.println("Y for YOfLastElement = " + YOfLastElement);

    int XOfSecondLastElement = allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-2).getLocation().getX();
    int YOfSecondLastElement =  allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-2).getLocation().getY();

    System.out.println("X for XOfSecondLastElement = " + XOfSecondLastElement);
    System.out.println("Y for YOfSecondLastElement = " + YOfSecondLastElement);

    while(true){
        for(int i = 0 ;i<allContactsOnfirstScreen.size();i++){
            System.out.println("Value is for " + allContactsOnfirstScreen.get(i).getAttribute("text")); 
        }
        driver.swipe(XOfLastElement, YOfLastElement, XOfFirstElement, YOfFirstElement, 1000);
        Thread.sleep(1000L);
        String LastName = allContactsOnfirstScreen.get(allContactsOnfirstScreen.size()-1).getAttribute("text");
        if(LastName.equals("MyLastContactText"))
            break;
    }

現在の問題は次のとおりです。>すべてが期待どおりに機能していますが、重複した値(連絡先)が出力されることがあります(その連絡先の座標がスワイプ後に変更されないことが原因である可能性があります)2.できません最後の連絡先の名前を毎回出力すると、while ループ内の if ステートメントが原因で、スクリプトが停止します。

誰かが助けてくれるなら、新しい方法があれば教えてください。よろしくお願いします。

4

1 に答える 1