Reputation: 1265
I can't figure out how to click on the sign-in element (from UI Automator):
Keep in mind there are multiple TextView-s with 0-index in the UI. Can I use its text ("Sign in") or its unique ListView/TextView path somehow?
Upvotes: 1
Views: 19366
Reputation: 77
You can use the class name and text for clicking. There is no need of building custom xpath for this.
List<WebElement> elements = driver.findElements(By.className("class"));
For(WebElement element:elements)
{
if(element.geText().equals("textProperty"))
{
element.click();
}
}
Upvotes: 0
Reputation: 51
Try this:
driver.findElement(By.xpath("//*[@class='android.widget.TextView' and @index='0']")).click();
OR
driver.findElement(By.name("Sign In")).click();
Ideally Both should work.
Upvotes: 2
Reputation: 51
Try this, should work.
driver.findElement(By.xpath("//android.widget.TextView[@index='0']")).click();
Upvotes: 3
Reputation: 1370
There are two ways to do it:
First, try this:
driver.findElementByName("SignIn").click();
Second, try this:
public void tap(int index){
List<WebElement> li = driver.findElementByClass("PUT YOUR class name");
li.get(0).click();
}
Upvotes: 4
Reputation: 231
In native android automation I do something like,
onData(anything())
.inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView()))))
.atPosition(0).atPosition(1)
.perform(click()); //this click item in droplist within droplist
or
onView(findChildof(withId(R.id.parent_id), 3)).check(matches((isDisplayed()))).perform(click()); //this clicks third child
Upvotes: 2
Reputation: 2766
I don't know what version of Android you are running on, but what you can do is
1) You can try to add content description to XML element search for it.
2) You can search by text as you said, such as searching for name ("Sign in").
3) You can access using XPath.
I would recommend setting up Appium Ruby Console, so you can test commands in real time and see what works best for you.
Upvotes: 2