Kaarel Purde
Kaarel Purde

Reputation: 1265

[android][appium] how to click on element with no resource-id?

I can't figure out how to click on the sign-in element (from UI Automator): enter image description here

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

Answers (6)

Prajeeth Anand
Prajeeth Anand

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

Tanmay
Tanmay

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

Tanmay
Tanmay

Reputation: 51

Try this, should work.

driver.findElement(By.xpath("//android.widget.TextView[@index='0']")).click();

Upvotes: 3

Gaurav
Gaurav

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

StackTrace
StackTrace

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

Gokhan Arik
Gokhan Arik

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

Related Questions