Handling Spinner Using Appium


Spinner
import java.net.URL;
import java.util.List;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example12SpinnerApiDemo {
   
    public static void main(String[] args) throws Exception {
    DesiredCapabilities dc= new DesiredCapabilities();
       
        dc.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
       
        dc.setCapability(MobileCapabilityType.PLATFORM_VERSION, "5.1");//Version is number here
       
        dc.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");

        dc.setCapability(MobileCapabilityType.APP, "C:\\apkfiles\\ApiDemos.apk");
       
        URL url =new URL("http://127.0.0.1:4723/wd/hub");

        AndroidDriver driver= new AndroidDriver(url,dc);
               
        driver.findElementsById("android:id/text1").get(10).click(); //Views
               
        //scrolling down till we get the element
                MobileElement listitem = (MobileElement) driver.findElement(
                        MobileBy.AndroidUIAutomator(
                                "new UiScrollable(new UiSelector()).scrollIntoView("
                                        + "new UiSelector().description(\"Spinner\"));"));
               
                listitem.click(); //click on spinner
               
        //lets handle color for now
        Thread.sleep(1500);
       
        //it is 1st spinner io.appium.android.apis:id/spinner1
        driver.findElementById("io.appium.android.apis:id/spinner1").click();
       
        driver.findElementsById("android:id/text1").get(3).click();
               
        Thread.sleep(9500);
        driver.quit();   

               
    }

}

No comments:

Post a Comment

FOLLOWERS