Find first clickable ancestor node

Hi,
I’m using Appium to do uiAutomation on Android application.

Currently I’m using :

  • appium v1.6.3
  • java-client 5.0.0-BETA5

And the followins is my problem :

Using xPath I would select the first clickable ancestor of a node.

For example :

| FrameLayout  clickable true
|    LinearLayout  clickable false
|        TextView "pluto"  cliackable false  

For example if I want select the first clickable ancestor of the TextView that contains this text String “pluto” than the xpath has to return the FrameLayout node

In this other example :

| FrameLayout  clickable true
|    LinearLayout  clickable false
|        TextView "pluto"  cliackable true

the xpath has to return the TextView node

I have to do in this way because in my layout I have different Layout ( similar to the above examples ) and I have to click on the one that contains a textView with a specific String.

Initially I try to select the textView in this way :
String xpath = "//android.widget.TextView[@resource-id="com.example.appium:id/idlable" and @text='pluto']"

and perform the click in the text ora element in the following way:

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebElement element = driver.findElementByXPath(xpath);
element.click()

But it doesn’t work, the click is not executed; I suppose happen because the textview is not a clickable node and infact if I do in the following way :

WebElement element = driver.findElementByXPath(xpath);
Point point = element.getLocation();
TouchAction click = new TouchAction(driver);
click.tap(point.getX(),point.getY()).perform();

it works, but some times the click is performed in wrong place maybe because appium find the element before it is in the final correct position.

Edit : my principal layout is inside a scroolview