XPath-如何通过包含新行的@text选择 [英] XPath - How to select by @text that contains new line
问题描述
在移动应用程序"视图中,我看到这样的文本:
In the Mobile application view I see text like this:
测试字符串
换行
但是在该视图的元素树中(它看起来像可扩展的树查看器),我看到了该视图的@text属性的值,如下所示:
But in the elements tree of this view (it looks like expandible tree viewer) I see value of the @text attribute of this one like this:
用新行测试字符串
我尝试使用以下方式:
xpath=//*[@text='Test string\nwith new line']
xpath=//*[@text=concat('Test string','\n','with new line']
但是它们不起作用.
是否可以通过包含新行的@text属性来选择元素? 如果可能的话,该怎么做?
Is it possible to select element by its @text attribute containing new line? If it is possible How to do that?
注意:我无法查看源代码并进行更改.
Note: I don't have ability to see source code and change it.
推荐答案
我不知道将单个换行符放入XPath的好方法,但是如果主要目的是选择normalize-space()
,则可以使用normalize-space()
元素及其包含换行符的事实并不那么重要:
I don't know of a good way to place a single newline character into an XPath, but you could use normalize-space()
if your main objective is to select the element and the fact that it contains a newline isn't all that important:
//*[normalize-space(@text) = 'Test string with new line']
这篇关于XPath-如何通过包含新行的@text选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!