xpath in normalize-space usage [Reserved]

The following menu to click on the "freight performance", we look at xpath, all menu items id is "vertab", it can not be used to locate the id, then first try to use xpath text

// a [text () = 'freight performance']

 

Found not locate, because after the text "freight performance" spaces and line breaks, then try using xpath contains text

// a [contains (text (), 'the performance of freight')]

But the menu there is a "non-freight performance", the text also contains "freight performance", apparently not

 

 

Try this into

// a [contains (text (), 'freight performance') and not (contains (text (), 'non-freight performance'))]

 

 

A match is found to a number of original pages there are other places to meet this condition, said earlier, there are several of the menu items have a common id, id then add conditions to try

// a [@ id = 'vertab' and contains (text (), 'freight performance') and not (contains (text (), 'the non-performance of freight'))]

This time it

Is there an easier way to do that, a variety of languages ​​which have a space before and after removal method, xpath do not you?

The answer is: Yes

normalize-space this method can remove the front and back spaces and carriage returns in the text, so write

// a [normalize-space (text ()) = 'freight performance']

On it.

Guess you like

Origin www.cnblogs.com/wanglingjiang/p/11269856.html