Android app illegal xpath

i used spy to capture the XPath from the app
code:

int j=1
j++

String path = ‘//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[3]/android.view.ViewGroup[1]/android.widget.RelativeLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.LinearLayout[1]/android.support.v7.app.ActionBar$Tab[’+j+‘]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]’

TestObject to = findTestObject(‘Android Sanity/Events/when’)

to.findProperty(‘xpath’).setValue(path)

Mobile.tap(to, GlobalVariable.TIMEOUT_LONG)

Error:

Test Cases/movies/android/headers/Verify Events Link redirection FAILED because (of) Failed to tap on element ‘Object Repository/Android Sanity/Events/when’ (Root cause: org.openqa.selenium.WebDriverException: Returned value cannot be converted to List: {stacktrace=UnknownError: An unknown server-side error occurred while processing the command. Original error: io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: xPathString=//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[3]/android.view.ViewGroup[1]/android.widget.RelativeLayout[1]/android.widget.HorizontalScrollView[1]/android.widget.LinearLayout[1]/android.support.v7.app.ActionBar$Tab[2]/android.widget.RelativeLayout[1]/android.widget.LinearLayout[1]

at io.appium.uiautomator2.model.XPathFinder.(XPathFinder.java:84)

at io.appium.uiautomator2.model.XPathFinder.getNodesList(XPathFinder.java:121)

at io.appium.uiautomator2.handler.FindElements.getXPathUiObjects(FindElements.java:61)

at io.appium.uiautomator2.handler.FindElements.findElements(FindElements.java:139)

at io.appium.uiautomator2.handler.FindElements.safeHandle(FindElements.java:85)

at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:56)

at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:239)

at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:230)

at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)

at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)

at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)

at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)

at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)

at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)

at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)

at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)

at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)

at java.lang.Thread.run(Thread.java:764)

Caused by: javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: Extra illegal tokens: ‘$’, ‘Tab’, ‘[’, ‘2’, ‘]’, ‘/’, ‘android.widget.RelativeLayout’, ‘[’, ‘1’, ‘]’, ‘/’, ‘android.widget.LinearLayout’, ‘[’, ‘1’, ‘]’

at org.apache.xpath.jaxp.XPathImpl.compile(XPathImpl.java:408)

at io.appium.uiautomator2.model.XPathFinder.(XPathFinder.java:82)

… 34 more

Caused by: javax.xml.transform.TransformerException: Extra illegal tokens: ‘$’, ‘Tab’, ‘[’, ‘2’, ‘]’, ‘/’, ‘android.widget.RelativeLayout’, ‘[’, ‘1’, ‘]’, ‘/’, ‘android.widget.LinearLayout’, ‘[’, ‘1’, ‘]’

at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:610)

at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:145)

at org.apache.xpath.XPath.(XPath.java:178)

at org.apache.xpath.XPath.(XPath.java:266)

at org.apache.xpath.jaxp.XPathImpl.compile(XPathImpl.java:400)

… 35 more

at errorFromMJSONWPStatusCode (/usr/local/lib/node\_modules/appium/node\_modules/appium-base-driver/lib/protocol/errors.js:772:10)

at ProxyRequestError.getActualError (/usr/local/lib/node\_modules/appium/node\_modules/appium-base-driver/lib/protocol/errors.js:674:14)

at asyncHandler$ (/usr/local/lib/node\_modules/appium/node\_modules/appium-base-driver/lib/protocol/protocol.js:345:25)

at tryCatch (/usr/local/lib/node\_modules/appium/node\_modules/babel-runtime/regenerator/runtime.js:67:40)

at GeneratorFunctionPrototype.invoke \[as \_invoke\] (/usr/local/lib/node\_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)

at GeneratorFunctionPrototype.prototype.(anonymous function) \[as next\] (/usr/local/lib/node\_modules/appium/node\_modules/babel-runtime/regenerator/runtime.js:100:21)

at GeneratorFunctionPrototype.invoke (/usr/local/lib/node\_modules/appium/node\_modules/babel-runtime/regenerator/runtime.js:136:37), error=unknown error, message=An unknown server-side error occurred while processing the command. Original error: io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: xPathString=//hierarchy/android.widget.FrameLayout\[1\]/android.widget.LinearLayout\[1\]/android.widget.FrameLayout\[1\]/android.widget.FrameLayout\[1\]/android.widget.FrameLayout\[1\]/android.view.ViewGroup\[1\]/android.widget.FrameLayout\[1\]/android.widget.LinearLayout\[1\]/android.widget.LinearLayout\[3\]/android.view.ViewGroup\[1\]/android.widget.RelativeLayout\[1\]/android.widget.HorizontalScrollView\[1\]/android.widget.LinearLayout\[1\]/android.support.v7.app.ActionBar$Tab\[2\]/android.widget.RelativeLayout\[1\]/android.widget.LinearLayout\[1\]

at io.appium.uiautomator2.model.XPathFinder.(XPathFinder.java:84)

at io.appium.uiautomator2.model.XPathFinder.getNodesList(XPathFinder.java:121)

at io.appium.uiautomator2.handler.FindElements.getXPathUiObjects(FindElements.java:61)

at io.appium.uiautomator2.handler.FindElements.findElements(FindElements.java:139)

at io.appium.uiautomator2.handler.FindElements.safeHandle(FindElements.java:85)

at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:56)

at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:239)

at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:230)

at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)

at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)

at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)

at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)

at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)

at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)

at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)

at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)

at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)

at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)

at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)

at java.lang.Thread.run(Thread.java:764)

Caused by: javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: Extra illegal tokens: ‘$’, ‘Tab’, ‘[’, ‘2’, ‘]’, ‘/’, ‘android.widget.RelativeLayout’, ‘[’, ‘1’, ‘]’, ‘/’, ‘android.widget.LinearLayout’, ‘[’, ‘1’, ‘]’

at org.apache.xpath.jaxp.XPathImpl.compile(XPathImpl.java:408)

at io.appium.uiautomator2.model.XPathFinder.(XPathFinder.java:82)

… 34 more

Caused by: javax.xml.transform.TransformerException: Extra illegal tokens: ‘$’, ‘Tab’, ‘[’, ‘2’, ‘]’, ‘/’, ‘android.widget.RelativeLayout’, ‘[’, ‘1’, ‘]’, ‘/’, ‘android.widget.LinearLayout’, ‘[’, ‘1’, ‘]’

at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:610)

at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:145)

at org.apache.xpath.XPath.(XPath.java:178)

at org.apache.xpath.XPath.(XPath.java:266)

at org.apache.xpath.jaxp.XPathImpl.compile(XPathImpl.java:400)

… 35 more

}

Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’

System info: host: ‘pritamsenMacMini.local’, ip: ‘fe80:0:0:0:1c3b:cad9:ad8c:77b0%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.13.4’, java.version: ‘1.8.0_102’

Driver info: driver.version: AppiumDriver)

Hi pritam

Use the below mentioned solution instead of /android.support.v7.app.ActionBar$Tab[’+j+’]. It might work for you.

“//*[contains(name(), ‘ActionBar’ )][”+j+"]"

Hello everyone,

This bug is fixed in version 7.6.5, a pre-release, which is available here. For more details regarding this version, you can find in Release notes version 7.6.5.

Happy Testing
Jass