Driver exception for xpath

Hello,
I’m experiencing an issue when dealing with some complex xpaths in Appium.

At the attempt to locate the following element:
“findElement(By.xpath (”//android.widget.RelativeLayout/*[contains(@text,‘abc’)]/following::android.widget.TextView[1]")); "

I get the error: “ClassCastException: java.util.ArrayList$ListItr cannot be cast to org.eclipse.wst.xml.xpath2.processor”.

The reason for that error is the “/following::android.widget.TextView[1]”".
Once I remove that part from the above xpath, the error goes away.

Unfortunately there’s no other identifiers available for that element.

Please advise on the issue.

Nope…
I did replace all the * with values, but had exactly the same error… :frowning:

Also how do I use the uiautomator/UiSelector to replicate the functionality of the “/following::” ?

→ see UiSelector  |  Android Developers

@Aleksei, thank you for your response!
I checked out the url and all possible methods available in there, but was unable to find anything that could be similar to “/following::”.

If possible could you pls re-write the above xpath selector by using uiautomator/UiSelector functionality?

PS: I wouldn’t want to downgrade Appium due to these issues and want to ask if there’s any way to enforce usage of xpath1.0 instead of xpath2.0 for Appium?

Have you eventually tried the enforceXPath1 setting from my comment above?

@mykola-mokhnach
Yes, I added “enforceXPath1=true” to the driver’s capabilities, but it made no difference :frowning:

This is not a capability, but a setting. Settings works differently: https://appium.io/docs/en/advanced-concepts/settings/

@mykola-mokhnach,
When I do:

driver.setSetting(“enforceXPath1”,true);

I get another error:

Setting ‘enforceXPath1’ is not supported. Only the following settings are supported: [actionAcknowledgmentTimeout, allowInvisibleElements, ignoreUnimportantViews, elementResponseAttributes…

This is happening because you use an older version of it. Consider switching to Appium 2 to get access to the most recent uia2 driver version. appium 1 has not been maintained for months

One more question.
Do I understand it correctly that the functionality of uiautomator/UiSelector does not have anything to match the functionality of the xpath axis “/following::”?

for me it looks like
childSelector should work

childSelector looks for child widgets under a specific parent widget. That element has no children, and that’s why childSelector won’t work.

Share page source and point to el your need.

I was able to resolve this by setting “enforceXPath1” to true (appium v8.3.0)