Reputation:
I have a problem in setting the date from a date picker in Appium. I'm trying to set the date by sending keys in the fields in this way:
List<WebElement> pick = driver.findElements(By.className("android.widget.EditText"));
pick.get(0).sendKeys("21");
pick.get(1).sendKeys("Mar");
pick.get(2).sendKeys("1989");
This works fine in previous versions of API but since I'm testing in a different device now appium seems not to finding my elements correctly. Here is a photo from the inspector window that shows that I'm using the correct class to find the fields.
Any ideas?Thanks!!
Upvotes: 1
Views: 4141
Reputation: 3105
Not sure what's the problem because some information is missing, but maybe try using swipe
instead of sendKeys
, it doesn't look like a sendKeys field.
Anyway I can recommend a workaround that I'm using when I need to change the date while testing, you can use the following adb command:
adb shell date -s YYYYMMdd.HHmmss
It's much faster and reliable, hope this helps.
Upvotes: 2
Reputation: 43
I resolved this as shown below in the appium-java client as none of the above worked for me:
Android emulator API level: 28
Android emulator version: 9
Appium java client version: 5.0.4
currentMonthElement
in the code below is the WebElement
that represents the month field in the datepicker. You can use find by xpath or whichever way you like to find this element using driver.findElement
. The below code can be reused to enter value for date and year elements. In the place of currentMonthElement
variable, please pass the date and year elements.
touchAction.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(currentMonthElement))).release().perform();
driver.getKeyboard().sendKeys(Keys.DELETE);
String monthstr = "Aug";
while(!currentMonthElement.getText().equals(monthstr)){
driver.getKeyboard().sendKeys("Aug");
}
//click on ok button after setting the date, month & year
driver.findElement(By.id("button1")).click();
Upvotes: 0
Reputation: 23
Perform This way
List<WebElement> textFieldsList = driver.findElements(By.className("android.widget.EditText"));
int size = textFieldsList.size();
textFieldsList.get(0).sendKeys("test");
textFieldsList.get(1).sendKeys("test");
textFieldsList.get(2).sendKeys("[email protected]");
Upvotes: 0
Reputation: 129
Perform action with xpath
// Select month name in datepicker
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='0']")).sendKeys("Jan");
// Select day in datepicker
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='1']")).sendKeys("24");
// Select year in datepicker
driver.findElement(By.xpath("//android.widget.NumberPicker[@index='2']")).sendKeys("1987");
Upvotes: 0