Java & Appium: Unable To Click Element
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 & th
Solution 1:
Here's the solution that worked for me:
- Use MobileElement. I am using AndroidDriver also instead of RemoteWebDriver so I do not know whether that will work or not.
- Forget click(). Use tap(int fingers, int duration) method of MobileElement. I have not found on the internet what duration is (seconds, milliseconds, etc so these values are just hit & trial).
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
// change hour@SuppressWarnings("unchecked")
List<WebElement> buttons = driver.findElementsByClassName("android.widget.Button");
MobileElement hour = (MobileElement) buttons.get(0);
List<WebElement> highlights = driver.findElementsByClassName("android.widget.EditText");
MobileElement hourHighlight = (MobileElement) highlights.get(0); // highlighted hour// lets say we need hour = 4while (!hourHighlight.getText().equalsIgnoreCase("4"))
{
Thread.sleep(100);
if (hourHighlight.getText().equalsIgnoreCase("4"))
{
break;
}
hour.tap(1, 10);
}
Solution 2:
I have tried to find an element by Text i.e '7' and it worked for me please try with:
driver.findElementsByName("7").click();
or
helpers.element(By.name("7")).click();
You can also use variable instead of text to click on specific Time
Let me know if it works
Solution 3:
Try this:
driver.findElementByName("7").click();
OR
driver.findElementByXPath("//*[@class='android.widget.button' and @text='7']").click();
Solution 4:
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')");
Solution 5:
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");
Post a Comment for "Java & Appium: Unable To Click Element"