Pages

Search This Blog

Sunday, July 6, 2014

How to use / and // in xpath

How to use / and // in xpath
Difference between / and //  
/

When / is used at the beginning of a path:

/div
it will define an absolute path to node "a" relative to the root. In this case, it will only find "a" nodes at the root of the XML tree.

//

When // is used at the beginning of a path:

//div

It will define a path to node "div" anywhere within the XML document. In this case, it will find "div" nodes located at any depth within the XML tree.

These XPath expressions can also be used in the middle of an XPath value to define ancestor-descendant relationships. When / is used in the middle of a path:

/div/a

Tt will define a path to node "a" that is a direct descendant (ie. a child) of node "div".

When // used in the middle of a path:

/div//a

It will define a path to node "a" that is any descendant (child node)  of node "div".

When we don't know the immediate parent of a child then we can use "." dot

will still find any node, "div", located anywhere within the XML tree. But, the XPath:

.//div

will find any node, "div", that is a descendant of the node . " In other words, preceding the "//" expression with a "." tells the XML search engine to execute the search relative to the current node reference.

10 comments:

  1. 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

    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. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing
    java training in chennai
    dot net training in chennai

    php 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. A nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.

    Some important links here,

    Selenium Training in Velachery | Best Selenium Training Institute in Chennai

    ReplyDelete
  8. Just wanted to say I love reading through your blog .thanks.
    บาคาร่า
    จีคลับ
    gclub

    ReplyDelete