Pages

Search This Blog

Sunday, July 6, 2014

How to find a sibling of a node

How to find a sibling of a node
There are many situation when we get difficulties to find the elements which do not have identification/attribute but their immediate siblings has some identification.




In above example if we want to get the text of H1 we can not use //h1 because there are more than one h1 on the page. If you see a and h1 both are siblings and children of div//[@class='title pad_btm15']
By using a sibling element's property we can find out his sibling. In above example we know id of a which is "mainContent" then we can get its sibling

Xpath:

"//a[@id='mainContent']/following-sibling::h1"


If you have more siblings with no attribute or no unique attribute like below.

then we can use the position us find out exact element using xpath:
Xpath:
Samsung Android Mobile
"//a[@id='mainContent']/following-sibling::h1[1]"

Nokia Android Mobile :
"//a[@id='mainContent']/following-sibling::h1[2]"

12 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. 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
  3. I got better idea in finding the sibling of a node. Please explain me the method to connect the node machine to hub machine in selenium for cross browser testing.
    Selenium Training in Chennai

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

    ReplyDelete
  5. 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
  6. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  7. This one is much helpful, Very clear explanation about the topic.

    Latest Update here: www.bestseleniumtraininginchennai.in

    ReplyDelete
  8. 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
  9. We can learn everyday something new in software testing. Automation is a topic that covers most of the part of testing and learning testing. Thanks for sharing this valuable information with a complete explanation.

    ReplyDelete