[appium驱动程序在使用正则表达式时抛出异常?

问题描述 投票:0回答:1

我正在使用appium做一些ui自动化。我在使用正则表达式时遇到了问题;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>
java selenium appium
1个回答
0
投票

您有两个问题:

  1. matches()仅在XPath 2.0中可用,而在1.0中不可用,请参阅:http://www.w3.org/TR/xquery-operators/#func-matches

硒,以及Chrome和Firefox浏览器都在使用Xpath 1.0。您可以在浏览器的JS控制台中尝试任何Xpath 2.0函数,它将显示一个错误。例如:$x("lower-case('ABC')")

  1. 要获取文本,请使用.text()例如$x("//*[contains(text(),'bob')]")

作为解决您的问题的方法,您可以获取包含文本"//android.view.View[contans(text(),'sometext')]")的所有元素,然后在JAVA中遍历它们以找到正确的元素

© www.soinside.com 2019 - 2024. All rights reserved.