简体   繁体   English

如何编写 XPath 来选择带有引号和逗号字符的文本?

[英]How to write an XPath to select text with a quote & comma character?

How can I select a XPath that contains a text with both quote & comma character?如何选择包含带有引号和逗号字符的文本的 XPath?

I have to find an element if the text contains = Yes, It's OK我必须找到一个元素,如果文本包含 =是的,没关系

My XPath does not save in ranorex tool even though if i put the text inside the double quotes like below我的 XPath 不会保存在 ranorex 工具中,即使我将文本放在双引号内,如下所示

//span[text()="Yes, It's OK"]

So how can I save this xpath that uses "".in Ranorex那么我该如何保存这个使用“.in Ranorex”的xpath

You have to escape the apostrophe, but not the comma:您必须转义撇号,但不能转义逗号:

//span[text()="Yes, It's OK"]

You can have a look at a list of predefined XML entities over at WikiPedia .您可以在 WikiPedia 上查看预定义 XML 实体的列表

your use of double-quotes is correct.您使用双引号是正确的。 if如果

//span[text()="Yes, It's OK"]

doesn't match, it might be because the xpath engine has a lowercase bug (i have encountered PHP+DOMXPath+libxml2 systems where it would only match lowercase text even for text with uppercase characters, never quite figured out the problem there), or it might be because the text has hidden whitespace you're not aware of, maybe it actually has a hard-to-spot whitespace at the start or the end?不匹配,这可能是因为 xpath 引擎有一个小写错误(我遇到过 PHP+DOMXPath+libxml2 系统,它只会匹配小写文本,即使对于带有大写字符的文本,也从来没有完全弄清楚那里的问题),或者可能是因为文本隐藏了您不知道的空格,也许它实际上在开头或结尾有一个难以发现的空格? anyway maybe contains() will work:无论如何也许 contains() 会起作用:

//span[contains(text(),"Yes, It's OK"]

or.. if it has the lowercase-issue i have encountered in the wild once before, maybe this will work:或者..如果它有我以前在野外遇到过的小写问题,也许这会起作用:

//span[contains(text(),"yes, it's ok"]

(that really shouldn't be required, but i have been in that situation once before, and that was years ago, and that was... probably php5) (这真的不应该被要求,但我曾经遇到过这种情况,那是几年前的事了,那是......可能是 php5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM