如何解决“不是有效的Xpath表达式”柏树错误?
我使用此字符串来找到一个元素:
cy.xpath('//*[text()="search ${keyword}")]')
当我运行测试时,它显示了控制台的正确结果,但也向我显示了此错误:
无法在“文档”上执行'评估':字符串
'//*[text()=“ search $ {键word}”)]'
不是有效的xpath表达式。<<<<<<<<< /p>
I used this string to find an element:
cy.xpath('//*[text()="search ${keyword}")]')
And when I run my test, it shows me the right result in console but also it shows me this error:
Failed to execute 'evaluate' on 'Document': The string
'//*[text()="search ${keyword}")]'
is not a valid XPath expression.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用了包含,并且可以工作。
我的XPath中有一个图标,它找不到文本。
I used contains and it works.
there is an icon in my XPath and it couldn't find just the text.
您原始问题的问题
是实际的语法错误是由于无关的
)
:删除该字符以消除语法错误。
您的自我答复
您的解决方案,
您可能会认为它可能会做的。 (它仅检查 first
text()
每个元素的子女的子字符串。)有关详细信息,请参见此广泛的解释。根据您的要求,使用
或使用链接说明中显示的其他变体。
Issue with your original question
The actual syntax error is due to an extraneous
)
:Delete that character to eliminate the syntax error.
Issue with your self-answer
Your solution,
doesn't do what you likely think it does. (It's only checking for substrings within the first
text()
node child of every element.) For full details, see this extensive explanation.Instead, use
or the other variation shown in the linked explanation per your requirements.