XPath - How to select by @text that contains new line

时光怂恿深爱的人放手 提交于 2019-12-12 15:32:38

问题


In the Mobile application view I see text like this:

Test string

with new line

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:

Test stringwith new line

I have tried to use the following ways:

xpath=//*[@text='Test string\nwith new line']

xpath=//*[@text=concat('Test string','\n','with new line']

But they don't work.

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.


回答1:


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']


来源:https://stackoverflow.com/questions/28404962/xpath-how-to-select-by-text-that-contains-new-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!