Handling Date Picker/Time Using Appium


Date Picker/Time
import java.net.MalformedURLException;
import java.net.URL;

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

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class Example11DatePicker {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {
       
        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

        driver.findElementsById("android:id/text1").get(6).click();//Date Widgets
       
        driver.findElementByAccessibilityId("2. Inline").click(); //Inline
       
               
        //Hours
        driver.findElementById("android:id/hours").clear();
        driver.findElementById("android:id/hours").sendKeys("10");
       
       
        //MinUTS
        driver.findElementById("android:id/minutes").clear();
        driver.findElementById("android:id/minutes").sendKeys("10");
       
       
        //am
        driver.findElementById("android:id/am_label").click();
       
        Thread.sleep(10000);
       
       
        driver.quit();

    }

}

Followers