Trim / Remove spaces in Xpath?



If you are wondering how you can trim the spaces in your xpath, this is how:

The normalize-space function strips leading and trailing white-space from a string, replaces sequences of white-space characters by a single space, and returns the resulting string.

Example : Which one is better?
//td[starts-with(normalize-space(),'Text to Trim')]
//td[starts-with(normalize-space(text()),'Text to Trim')]
The second option is better as it targets at the specific nodes


More string functions in XPATH:

FunctionsDescription
starts-with(string1string2)Returns true if the first string starts with the second string.
contains(string1string2)Returns true if the first string contains the second string.
substring(stringoffsetlength)Returns a section of the string. The section starts at offset
(which is a number), and is as long as the value provided at length.
substring-before(string1string2)Returns the part of string1 up until the first occurence of string2.
substring-after(string1string2)Returns the part of string1 after the first occurence of string2.
string-length(string)Returns the length of string (i.e. the number of characters).
normalize-space(string)Trims the leading and trailing space from string.
Also replaces consecutive occurrences of white space with a single space.
translate(string1string2string3)Returns string1 after any matching characters in string2 have been
replaced by the characters in string3.
concat(string1string2...)Concatenates all strings (i.e. joins them together).
format-number(number1string1,string2)Returns a formatted string version of number1 after applying string1 as
a format string. string2 is an optional locale string.


Comments

  1. Thanks for your great and helpful presentation I like your good service. I always appreciate your post. That is very interesting I love reading and I am always searching for informative information like this.angular 4 training in chennai | angularjs training in chennai | .angularjs best training center in chennai | angularjs training in velachery |

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Thank you so much for this nice information. Hope so many people will get aware of this and useful as well. And please keep update like this.

    Text Analytics Software

    Sentiment Analysis Tool

    ReplyDelete

  6. I such a lot unquestionably will make sure to do not disregard this website and give it a look regularly.
    offshoreservers net

    ReplyDelete
  7. I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience. Fire Alarm Control Panel Price in Pakistan

    ReplyDelete
  8. I think this is the best article today. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future reference.Excellent blog admin. This is what I have looked. Check out the following links for Software testing companies USA
    Test automation software
    Best automated testing software
    Mobile app testing services
    Load testing services

    ReplyDelete
  9. I really appreciate this post and I like this very much. I am waiting for new post here and Please keep it up in future.

    CloudBox99 offers you with the best Cloud server hosting service in Hyderabad and facilitates enterprises to transform digitally. We keep you covered in terms of all your IT requirements with unmatched expertise and deep domain knowledge

    ReplyDelete
  10. Really you have done a good job. Thanks for sharing this valuable information....
    Inplant Training in Chennai
    PLC Training in Chennai
    Inplant Training in Chennai For CSE

    ReplyDelete
  11. Any one From CC&B?


    ReplyDelete
  12. If you stumbled upon this article while looking for a way to browse all the latest movies,
    you are, without a doubt, in the perfect place. We have the ideal solution for your problem,
    KatmovieHD 2020.

    visit more:
    Kuttymovies ,
    Khatrimaza,
    Downloadhub,
    Einthusan,
    123 Movies,
    7starHD,
    SkymoviesHD,
    MovieRulz

    ReplyDelete
  13. This is a really informative knowledge, Thanks for posting this informative Information. AZ-800: Administering Windows Server Hybrid Core Infrastructure

    ReplyDelete

  14. Nice Content, good information shared..
    Inovies

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Nice Article!

    Thanks for sharing with us 🙂

    Cyber Security Course in Hyderabad

    ReplyDelete

Post a Comment

Popular posts from this blog

Software Testing @ Microsoft