Using XPATH to search text containing whitespace

后端 未结 2 2032
囚心锁ツ
囚心锁ツ 2021-02-20 11:19

In


  Create Network Container         


        
2条回答
  •  鱼传尺愫
    2021-02-20 11:34

    It works by cutting and pasting your posted example. Your original source probably has tabs or other whitespace characters that don't match. Here are some alternatives:

    1) Normalize spaces

    //td[normalize-space(text()) = 'Create Network Container']
    

    2) Compare using string value of td (this will also match Create Network Container)

    //td[normalize-space(.) = 'Create Network Container']
    

    3) Check for each word separately (ignores word order)

    //td[contains(text(), 'Create') and contains(text(), 'Network') and contains(text(), 'Container')]
    

    4) Strip whitespace, tabs, newlines, line-feeds, carriage returns and compare result:

    //td[translate(text(), "  
    	
    ", "") = 'CreateNetworkContainer']
    

提交回复
热议问题