Q:

appium driver throws Exception when using regex?

I am using appium to do some ui automation.I am having problems with regex;
WebDriverException throwed with the code,and the element totally exists:
phonedriver.findElement(By.xpath("//android.view.View[matches(@text,'sometext\\d+')]")) 
Here are exception message:  
An unknown server-side error occurred while processing the command. Original error: java.lang.IllegalStateException: Unable to evaluate expression. See cause

Here are my capability info:  
Capabilities {appActivity: com.tencent.mm.ui.LauncherUI, appPackage: com.tencent.mm, deviceName: 127.0.0.1:62001, fastReset: false, fullReset: false, newCommandTimeout: 999999, noReset: true, platformName: Android, platformVersion: 5.1.1, resetKeyboard: true, udid: 127.0.0.1:62001}

Here are my pom:  
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.3.0</version>

<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>

A:

You have two issues:

matches() is only available in XPath 2.0 and not 1.0 see: http://www.w3.org/TR/xquery-operators/#func-matches

Selenium, but also Chrome and Firefox browser are using Xpath 1.0. 
You can try any Xpath 2.0 functions in the JS-console of the browser and it will show you an error. e.g.: $x("lower-case('ABC')")

to get the text use . or text() e.g $x("//*[contains(text(),'bob')]")

As a solution for your problem, you can get all elements containing your text "//android.view.View[contans(text(),'sometext')]") and then loop through them in JAVA to find the correct one

