@jitenderbhardwaj here is code to try:
Page object itself:
package com.zzzzz.pages.android;
import com.zzzz.base.Page;
import io.appium.java_client.MobileDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.HowToUseLocators;
import io.appium.java_client.pagefactory.LocatorGroupStrategy;
import org.openqa.selenium.WebDriver;
import java.time.Duration;
import java.util.List;
public class TestPage extends Page {
@HowToUseLocators(androidAutomation = LocatorGroupStrategy.CHAIN)
@AndroidFindBy(id = "picker_container")
@AndroidFindBy(id = "numberpicker_input")
private List<AndroidElement> pickerInputs;
@HowToUseLocators(androidAutomation = LocatorGroupStrategy.CHAIN)
@AndroidFindBy(id = "picker_container")
@AndroidFindBy(className = "android.widget.Button")
private List<AndroidElement> pickerButtons;
public TestPage(WebDriver driver) {
super(driver);
}
public boolean tapPickerButton(int num) {
System.out.println(" tapPickerButton(): " + num);
return tapElement(pickerButtons.get(num));
}
public String getPickerInputValue(int num) {
System.out.println(" getPickerInputValue(): " + num);
return pickerInputs.get(num).getText();
}
public boolean setPickerInputValue(int num, String input) {
System.out.println(" getPickerInputValue(): " + num);
try {
pickerInputs.get(num).setValue(input);
return true;
} catch (Exception e) {
// picker input num NOT found
return false;
}
}
public boolean tapElement(MobileElement element) {
try {
new TouchAction((MobileDriver) driver).press(element).waitAction(Duration.ofMillis(70)).release().perform();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
now test code itself:
TestPage testPage = new testPage(driver);
System.out.println("First picker value is: " + testPage.getPickerInputValue(1));
assertTrue("some error text", testPage.tapPickerButton(1));
System.out.println("First picker value changed to: " + testPage.getPickerInputValue(1));