In the Android app that I am testing, I am trying to click/tap the time picker. For example by default the time picker shows 08:00AM. I want to change the hour from 8 to 7 & then later on change the minutes but the xpath doesn't seem to be working. Its clicking something but the time still shows 08:00AM when I click the OK button via the code. If someone could help me then I will be able to change minutes & PM to AM as well.
Here's what I am using for tapping the hour picker so that 7 shows up selected:
driver.findElement(By.xpath("//android.widget.NumberPicker[0]/android.widget.Button[0]")).click();
Image:
Instead of clicking the number in NumberPicker, use SendKey.
WebElement hour= driver.findElement(By.xpath("//android.widget.TimePicker[1]/android.widget.NumberPicker[0])); hour.sendKeys("8");
Here's the solution that worked for me:
I have posted the code below & it worked. It may need refinement but for now I am happy as I am not a hardcore programmer.
Now assume that hour is variable depending upon your test
If you want to try javascript what I found worked for Android devices when regular touches and clicks didn't register anything was this:
js.executeScript("$('# pageElement .elementClassName').trigger('touchstart')");
I have tried to find an element by Text i.e '7' and it worked for me please try with:
You can also use variable instead of text to click on specific Time
Let me know if it works
Try this:
OR