Regex 使用正则表达式的selenium xpath表达式中出现语法错误

Regex 使用正则表达式的selenium xpath表达式中出现语法错误,regex,firefox,selenium,xpath,selenium-webdriver,Regex,Firefox,Selenium,Xpath,Selenium Webdriver,在Selenium 2.42.2和Firefox 29中,使用正则表达式的XPath表达式有什么问题: //button[matches(text(),'\s*ABC\s*')] 它给出以下错误消息: [Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: "<unknown>"] [异常…”表达式不是

在Selenium 2.42.2和Firefox 29中,使用正则表达式的XPath表达式有什么问题:

//button[matches(text(),'\s*ABC\s*')]
它给出以下错误消息:

[Exception... "The expression is not a legal expression."  code: "12" nsresult: "0x805b0033 (SyntaxError)"  location: "<unknown>"]
[异常…”表达式不是合法表达式。“代码:“12”nsresult:“0x805b0033(SyntaxError)”位置:“”
匹配()。在xpath支持方面,SeleniumWebDriver,在您的例子中是Firefox,据我所知

1.0中有很多函数可以帮助您解决这个问题

例如,
包含()

如果文本位于字符串的开头或结尾,则可以应用
start-with()
ends-with()

另请参见此相关线程:


@Solver很好,谢谢。据我所知,Firefox不支持2.0。另请参见:.@Solver也已找到,但仍处于打开状态。这可能是xpath 2.0不受支持的可靠迹象。您能分享一下不接受答案的原因吗?可能有smth需要改进吗?谢谢
//button[contains(., 'ABC')]
//button[starts-with(., 'ABC')]
//button[ends-with(., 'ABC')]