What's the difference between //node and /descendant::node in xpath?

前端 未结 4 780
执念已碎
执念已碎 2020-12-14 15:34

I use a lot of XPath when locating elements in web pages using Selenium, and have moved away from using node1//node2 towards using node1/descendant::node2 more recently. Wha

4条回答
  •  佛祖请我去吃肉
    2020-12-14 16:00

    see http://www.w3.org/TR/xpath#path-abbrev

    // is just an abbreviation for the descendant:: axis

    Edit

    To quote:

    //para is short for /descendant-or-self::node()/child::para

    That is, it refers to all para which are a child of the context node or any node descended from the context node. As far as I can tell that translates into any descendant para of the context node.

提交回复
热议问题