Using XPATH to search text containing whitespace

后端 未结 2 2033
囚心锁ツ
囚心锁ツ 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 <b>Network</b> 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(), "  &#13;&#10;&#09;&#xa;", "") = 'CreateNetworkContainer']
    
    0 讨论(0)
  • 2021-02-20 11:39

    Try this:

    //td[matches(text(), '\s*Create\s+Network\s+Container\s*')]
    

    To be honest this works for me in several evaluators I checked it in:

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

    Previous try was to match all potential space-like characters that might be there (perhaps it's not just a single whitespace there and that's why this simpliest solution doesn't give you proper results.

    0 讨论(0)
提交回复
热议问题