appium 驱动程序在使用正则表达式时抛出异常?
appium driver throws Exception when using regex?
我正在使用 appium 做一些事情 ui automation.I 正则表达式有问题;
WebDriverException 代码抛出,元素完全存在:
phonedriver.findElement(By.xpath("//android.view.View[matches(@text,'sometext\d+')]"))
以下是异常消息:
An unknown server-side error occurred while processing the command. Original error: java.lang.IllegalStateException: Unable to evaluate expression. See cause
这是我的能力信息:
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}
这是我的 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>
您有两个问题:
matches()
仅适用于 XPath 2.0 而不是 1.0 请参阅:http://www.w3.org/TR/xquery-operators/#func-matches
Selenium,还有 Chrome 和 Firefox 浏览器都使用 Xpath 1.0。
您可以在浏览器的 JS 控制台中尝试任何 Xpath 2.0 函数,它会向您显示错误。例如:$x("lower-case('ABC')")
- 获取文本使用
.
或 text()
例如 $x("//*[contains(text(),'bob')]")
作为您问题的解决方案,您可以获取包含您的文本的所有元素 "//android.view.View[contans(text(),'sometext')]")
,然后在 JAVA 中循环遍历它们以找到正确的元素
我正在使用 appium 做一些事情 ui automation.I 正则表达式有问题;
WebDriverException 代码抛出,元素完全存在:
phonedriver.findElement(By.xpath("//android.view.View[matches(@text,'sometext\d+')]"))
以下是异常消息:
An unknown server-side error occurred while processing the command. Original error: java.lang.IllegalStateException: Unable to evaluate expression. See cause
这是我的能力信息:
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}
这是我的 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>
您有两个问题:
matches()
仅适用于 XPath 2.0 而不是 1.0 请参阅:http://www.w3.org/TR/xquery-operators/#func-matches
Selenium,还有 Chrome 和 Firefox 浏览器都使用 Xpath 1.0。
您可以在浏览器的 JS 控制台中尝试任何 Xpath 2.0 函数,它会向您显示错误。例如:$x("lower-case('ABC')")
- 获取文本使用
.
或text()
例如$x("//*[contains(text(),'bob')]")
作为您问题的解决方案,您可以获取包含您的文本的所有元素 "//android.view.View[contans(text(),'sometext')]")
,然后在 JAVA 中循环遍历它们以找到正确的元素