[英]Search by exact text in xpath selenium
I have a question regarding xpath.我有一个关于 xpath 的问题。 I try to locate the element that is in a drop down for example Surveys when I try to search using contains it is working当我尝试使用 contains 进行搜索时,我尝试找到下拉列表中的元素,例如 Surveys
//li[contains(text(),'Surveys')]
But when I tried to search exact it is failed但是当我尝试精确搜索时它失败了
//li[text()='Surveys']
Can someone please advise?有人可以建议吗?
The text Surveys have a lot of white-spaces around it.文本Surveys周围有很多空白。 So alternatively to suppress the white-spaces you can use the following Locator Strategy :因此,为了抑制空白,您可以使用以下定位器策略:
//li[normalize-space()='Surveys']
使用normalize-space
删除空白字符:
//li[normalize-space(.)='Surveys']
Your "exact match" is missing the "new line" character, "\\n".您的“完全匹配”缺少“换行”字符“\\n”。 Try:尝试:
//li[text()='Surveys\n']
I have tried it before, but you can try a newer way, I am still using it and it is working fine我以前试过,但你可以试试更新的方法,我还在用它,它工作正常
right click --> copy XPath --> fix " "
右键单击 --> 复制 XPath --> 修复" "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.