Pages

Search This Blog

Sunday, July 6, 2014

How to use preceding-sibling and following-sibling in xpath to find sibling nodes

How to use preceding-sibling and following-sibling in xpath to find sibling nodes


How to get all the preceding siblings of Apple

Xpath: "//ul/li[contains(text(),'Apple Mobiles')]/preceding-sibling::li"

This will give "Samsung Mobiles"

How to get all the following  siblings of Apple
Xpath: "//ul/li[contains(text(),'Apple Mobiles')]/following-sibling::li"

This will give all the preceding siblings ( Nokia Mobiles, HTC Mobiles, Sony Mobiles, Micromax mobiles)

There is trick to use preceding-sibling and following-sibling. Place matters when you use this at beginning it will give you reverse result
When you use preceding-sibling at beginning then it will give result  ( Nokia Mobiles, HTC Mobiles, Sony Mobiles, Micromax mobiles) instead of Samsung mobiles.

Xpath : "//li[preceding-sibling::li='Apple Mobiles']"

This will give Samsung mobiles.
when you use following-sibling at the beginning then it will give reverse result. Instead of giving all below nodes of Apple mobile this will give Samsung Mobiles.
Xpath: "//li[following-sibling::li='Apple Mobiles']"
Now the question is how to get all the nodes between Apple Mobiles and Sony Mobiles.

Xpath : "//ul/li[preceding-sibling::li='Apple Mobiles' and following-sibling::li='Sony Mobiles']"
This will return Nokia Mobiles and HTC Mobiles.

or
Xpath : "//ul/li[preceding-sibling::li[.='Apple Mobiles'] and following-sibling::li[.='Sony Mobiles']]"
Or You can use this in contains as well
Xpath: "//ul/li[preceding-sibling::li[contains(text(),'Apple Mobiles')] and following-sibling::li[contains(text(),'Sony Mobiles')]]"

67 comments:

  1. i have a question regarding xpath following -sibiling
    there is application(http://www.zlti.com/)in that menus are there which contain list links.i want to mouseover one menu and get all the list of liks and test those links by clicking .For that i need script.i have tried upto mouseover menu and perform clicking operation.But not able to finding list of links.pls give solution for that scenario.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. https://chrome.google.com/webstore/detail/relative-xpath-helper/eanaofphbanknlngejejepmfomkjaiic

    ReplyDelete
  4. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  5. the best and very useful blogs for learner each and every concept explain in easy way thank you for sharing such a nice content.keep on update latest information all the best
    Selenium Online Training usa|uk|canada|australia

    ReplyDelete
  6. A nice article here, i think that people who have grown up with the idea of using computers are showing more responsibility towards writing posts that are thoughtful, do not have grammar mistakes and pertinent to the post..

    Selenium Training in Chennai

    ReplyDelete
  7. This is very informative blog and article thank you for sharing with us keep posting more information about salesforce trainingselenium training, selenium online training, selenium course,learn selenium course

    ReplyDelete
  8. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  9. A fantastic blog to know what Selenium is all about. It can be used in combination with many basic core programming languages for testing applications. Selenium online training in hyderabad, best selenium online course

    ReplyDelete
  10. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  11. thanks for sharing topic on How to use preceding-sibling really very useful post keep sharing

    Selenium Training in Chennai

    ReplyDelete
  12. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  13. Selenium Testing Real Time Hands on Training in Chennai…

    Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

    http://thecreatingexperts.com/selenium-training-in-chennai/

    If You need a Best Trainer in Selenium Testing??? Then be ready for a DEMO From the Trainer MR.Karthick
    CONTACT:8122241286

    Both Classroom/Online Training is Available!!!!!!

    ReplyDelete
  14. I have been surfing the internet for the past three hours and I have not come across such a site. It has not only a good design but also great content. I have learned a lot and I will nit mind visiting this site to read both new and old articles. Find time and read my article by clicking on Cheap Essay Writing Services.

    ReplyDelete
  15. Excellent ! I am truly impressed that there is so much about this subject that has been revealed and you did it so nicely.
    Selenium Training in Chennai

    ReplyDelete
  16. very informative blog with chapters covering SELENIUM, take a look at the link provided below to get hands on training with real time scenarios

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact info - 8122241286

    ReplyDelete
  17. nice blog has been shared by you.before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    selenium training in chennai

    ReplyDelete
  18. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  19. http://astrologershandeleyji.com/love-marriage-specialist-astrologer.php

    ReplyDelete
  20. thanks for this beautiful post of blog I really liked your blog, It is very goof for freshers
    Selenium training and Institute
    Selenium Training in Marathalli
    Selenium Course in Bangalore

    ReplyDelete
  21. Rated Best PLC, SCADA, DCS, HMI, Motors, AutoCAD Industrial Automation training company in Noida, Delhi NCR & offers hands on experience with placement support. We are conduct this course in Regular Training, weak end training, Short term training, Six Months training, Summer/winter training & Customized training for Incampus/colleges. Get details on +91- 9310096831.

    ReplyDelete
  22. At Coepd - (Center of Excellence for Professional Development) Manual & Selenium testing training program is designed to give participants the skills & knowledge to gain a competitive advantage in starting/enhancing a career in software testing. We provide the attendee's software testing service which is required to ensure that tested applications meet all application requirements. Participants receive up-to-date training in multiple areas in Software Testing and a thorough understanding of real-world projects. Our collaborative ecosystem comprising of Partnerships with Software Companies enables real time software test life cycle experience.

    http://www.coepd.com/TestingTraining.aspx

    ReplyDelete
  23. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.

    Online Robot Framework Training

    ReplyDelete
  24. You made such a fascinating piece to peruse, giving each subject illumination for us to grab learning. A debt of gratitude is for imparting the such data to us to peruse thisdevice testing manual

    ReplyDelete
  25. Very Very Nice Explanation.Really Thanks For Posting On Selenium Course

    ReplyDelete
  26. Thanks for the explanation.it was very clear to understand and looking forward for more updates on this topic. RPA training

    ReplyDelete
  27. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training Hyderabad

    ReplyDelete
  28. Do you have a spam issue on this website; I also am a blogger, and I wanted to know your situation; many of us have developed some nice methods, and we are looking to trade methods with others, why not shoot me an e-mail if interested.
    Hadoop Training in Bangalore
    Hadoop Training in Chennai

    ReplyDelete
  29. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
    MEAN stack training in Chennai
    MEAN stack training in bangalore

    ReplyDelete
  30. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.

    python training in chennai | python training in bangalore

    python online training | python training in pune

    python training in chennai

    ReplyDelete
  31. Really nice experience you have. Thank you for sharing. It will surely be an experience to someone.
    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  32. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Devops Training in pune

    Devops Training in Chennai

    Devops Training in Bangalore

    AWS Training in chennai

    AWS Training in bangalore

    ReplyDelete
  33. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in Chennai | rpa training in pune

    rpa training in tambaram | rpa training in sholinganallur

    rpa training in Chennai | rpa training in velachery

    rpa online training | rpa training in bangalore

    ReplyDelete
  34. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    rpa training in Chennai | rpa training in pune

    rpa training in tambaram | rpa training in sholinganallur

    rpa training in Chennai | rpa training in velachery

    rpa online training | rpa training in bangalore

    ReplyDelete
  35. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    python training in chennai
    python training in chennai
    python training in Bangalore

    ReplyDelete
  36. Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this. 
    java training in chennai | java training in bangalore


    java training in tambaram | java training in velachery

    ReplyDelete
  37. Greetings. I know this is somewhat off-topic, but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform like yours, and I’m having difficulty finding one? Thanks a lot.

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    AWS Online Training | Online AWS Certification Course - Gangboard

    ReplyDelete
  38. UiPath Training in Bangalore by myTectra is one the best UiPath Training. myTectra is the market leader in providing Robotic Process Automation on UiPath
    ui path training in bangalore

    ReplyDelete
  39. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Best Training Instittue


    ReplyDelete
  40. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    Best Training and Real Time Support

    Android Training From India

    Appium Training From India

    ReplyDelete
  41. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    python online training
    python training in OMR
    python training course in chennai

    ReplyDelete
  42. After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.

    angularjs

    Training in chennai


    angularjs-Training in chennai

    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    ReplyDelete
  43. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    Devops Training in pune

    ReplyDelete

  44. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.

    AWS Interview Questions And Answers

    AWS Training in Bangalore | Amazon Web Services Training in Bangalore

    AWS Training in Pune | Best Amazon Web Services Training in Pune

    Amazon Web Services Training in Pune | Best AWS Training in Pune

    AWS Online Training | Online AWS Certification Course - Gangboard

    ReplyDelete
  45. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.

    python Training in Bangalore | python Training in Bangalore

    ReplyDelete
  46. Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this.
    Golden gate Training Classes

    ReplyDelete