xpath
Parent
The parent axis contains only a maximum of one node. The parent node may be either the root node or an element node.the parent axis contains one node.
1) //*[@class='zOB73']/parent::*
Result à it will selects parent of the @class='zOB73' node

1) //*[@class='zOB73']/parent::div[1]àit will select first div node
2) //*[@class='zOB73']/parent::div à it will select all div nodes
Following
Following axis contains all nodes in the same document as the context node that are after the context node in document order.
Ex:1
//*[@class='zOB73']/following::div
Result à it will selects only div nodes after the current node

Ex2://*[@class='s2h6df']/following::*
Result -à it will selects all element nodes after the current node

Following Sibling
The following-sibling axis selects those nodes that are siblings of the context node (that
is, the context node and its sibling nodes share a parent node) and which occur later in
document order than the context node.
Ex:1//*[@class='gb_T']/following-sibling::div

Ex:1//*[@class='gb_T']/following-sibling::*

Ancestor
Selects all ancestors (parent, grandparent, etc.) of the current node
1) //*[@id='cst']/ancestor::div[@id='viewport']

2) //*[@id='searchform']/ancestor::div

3) //*[@id='cst']/ancestor::*

4) //*[@id='logocont']/ancestor::div[position()=3]

5) //*[@id='logocont']/ancestor-or-self::div
Ancestor-or-self lets you select any ancestors [e.g., Parent and Grandparent] of the current node including the current node.

Descendant
Selects all descendants (children, grandchildren, etc.) of the current node
1) //*[@id='viewport']/descendant::div
Result à it will display all div nodes from current node

1) //*[@class='s2h6df']/descendant::div[@class='HKjQUb']
Result à it will display specific node from current node

2) //*[@id='viewport']/descendant-or-self::div
Descendant-or-self lets you select all descendants [e.g., Children and Grandchildren] of the current node including the current node.

3) //*[@id='viewport']/descendant-or-self::div[3]
Resultà it will select 3rd position from then current node

Child
Selects all class nodes that are children of the current nodebecause below example we are selected class node
//*[@id='viewport']/child::div
Result à it will display all child nodes of current node specific to div node only
Note: other than div is there It will not select

//*[@id='viewport']/child::div[@id='gac_scont']
Result à it will display specific node from current node

Child :: *
//*[@id='viewport']/child::*
Result àSelects all element children of the current node

Child::Text()
Selects all text node children of the context node
Ex: //a/child::text()

Child::node()
Selects all children of the context node, whatever their node type
Note : it is very similar to child::*
Ex:1//*[@id='viewport']/child::*
![clip_image034[1] clip_image034[1]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM877OLFv5xbgwaJAw5kgeLiLsbH2Qol5IObu90T-HxMV0f8ExvKgOu2e6E7NvhCKy1OpVxz82gxFSJ838vJBAOu7NwIbT4ohPXiA-we9L5M17Bp3D1YwOaI8Mj2myRFCrCqNYxM7Nx2Q/?imgmax=800)
Ex 2: //*[@id='viewport']/child::div[position()=2]
Result à it will select child node of div which is on 2nd position

Preceding
The preceding axis contains all nodes in the same document as the context node that are before the context node in document order.
Ex:
//*[@id='viewport']/preceding::*
Result à it will select all element nodes before the current node

Ex 2:
//*[@id='main']/preceding::div
It will select only div nodes before the current node

Preceding – position
//*[@id='main']/preceding::div[position()=1]
Result: it will select node which Is on position 1 of div

Preceding –sibling
The preceding-sibling axis selects those nodes which are siblings of the context node (that is, the context node and its sibling nodes share a parent node) and which occur earlier in document order than the context node.
Ex1: //*[@id='main']/preceding-sibling::*
RESULT -à it will selects all element nodes before the current node of same level

Ex2: //*[@id='main']/preceding-sibling::div
RESULT -à it will selects all div nodes before the current node of same level

Ex:3: //*[@id='main']/preceding-sibling::div[position()>2]
Result à it will select all div nodes before the current node which is 2ndposition on wards

Attribute
Selects the attribute of the context node
Ex:1: //*[@id='viewport']/attribute::*
Selects the

Ex:2//*[@id='viewport']/attribute::class
Selects the

Ex:3
//div/attribute::class
Selects the

Ex: //div/a[text()="Gmail"]
Result àThis will find a link that has text ="Gmail"

Self
//*[@id='viewport']/self::*
Result àSelf returns the current node.

Few more examples:
Ex: //*[@id='viewport']/div[count(*)>0]àResult it will select all div node of the current node

Ex: //*[@id='viewport']/div[last()-3]
/*[last ()-3] describes the 4th upper node (div [2]) from last node.
Ex //div[@class='s2h6df']/child::div[position()=1]
Selects the first child of the context node

Ex: //div[@class='s2h6df']/child::div[position()=last()]
Selects the first child of the context node

Ex: //div[@class='s2h6df']/child::div[position()=last()-1]
Selects the last but one child of the context node

Ex: //div[@class='s2h6df']/child::div[position()>1]
Selects the all child node except first context node

Parent
The parent axis contains only a maximum of one node. The parent node may be either the root node or an element node.the parent axis contains one node.
1) //*[@class='zOB73']/parent::*
Result à it will selects parent of the @class='zOB73' node

1) //*[@class='zOB73']/parent::div[1]àit will select first div node
2) //*[@class='zOB73']/parent::div à it will select all div nodes
Following
Following axis contains all nodes in the same document as the context node that are after the context node in document order.
Ex:1
//*[@class='zOB73']/following::div
Result à it will selects only div nodes after the current node

Ex2://*[@class='s2h6df']/following::*
Result -à it will selects all element nodes after the current node

Following Sibling
The following-sibling axis selects those nodes that are siblings of the context node (that
is, the context node and its sibling nodes share a parent node) and which occur later in
document order than the context node.
Ex:1//*[@class='gb_T']/following-sibling::div

Ex:1//*[@class='gb_T']/following-sibling::*

Ancestor
Selects all ancestors (parent, grandparent, etc.) of the current node
1) //*[@id='cst']/ancestor::div[@id='viewport']

2) //*[@id='searchform']/ancestor::div

3) //*[@id='cst']/ancestor::*

4) //*[@id='logocont']/ancestor::div[position()=3]

5) //*[@id='logocont']/ancestor-or-self::div
Ancestor-or-self lets you select any ancestors [e.g., Parent and Grandparent] of the current node including the current node.

Descendant
Selects all descendants (children, grandchildren, etc.) of the current node
1) //*[@id='viewport']/descendant::div
Result à it will display all div nodes from current node

1) //*[@class='s2h6df']/descendant::div[@class='HKjQUb']
Result à it will display specific node from current node

2) //*[@id='viewport']/descendant-or-self::div
Descendant-or-self lets you select all descendants [e.g., Children and Grandchildren] of the current node including the current node.

3) //*[@id='viewport']/descendant-or-self::div[3]
Resultà it will select 3rd position from then current node

Child
Selects all class nodes that are children of the current nodebecause below example we are selected class node
//*[@id='viewport']/child::div
Result à it will display all child nodes of current node specific to div node only
Note: other than div is there It will not select

//*[@id='viewport']/child::div[@id='gac_scont']
Result à it will display specific node from current node

Child :: *
//*[@id='viewport']/child::*
Result àSelects all element children of the current node

Child::Text()
Selects all text node children of the context node
Ex: //a/child::text()

Child::node()
Selects all children of the context node, whatever their node type
Note : it is very similar to child::*
Ex:1//*[@id='viewport']/child::*
![clip_image034[1] clip_image034[1]](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM877OLFv5xbgwaJAw5kgeLiLsbH2Qol5IObu90T-HxMV0f8ExvKgOu2e6E7NvhCKy1OpVxz82gxFSJ838vJBAOu7NwIbT4ohPXiA-we9L5M17Bp3D1YwOaI8Mj2myRFCrCqNYxM7Nx2Q/?imgmax=800)
Ex 2: //*[@id='viewport']/child::div[position()=2]
Result à it will select child node of div which is on 2nd position

Preceding
The preceding axis contains all nodes in the same document as the context node that are before the context node in document order.
Ex:
//*[@id='viewport']/preceding::*
Result à it will select all element nodes before the current node

Ex 2:
//*[@id='main']/preceding::div
It will select only div nodes before the current node

Preceding – position
//*[@id='main']/preceding::div[position()=1]
Result: it will select node which Is on position 1 of div

Preceding –sibling
The preceding-sibling axis selects those nodes which are siblings of the context node (that is, the context node and its sibling nodes share a parent node) and which occur earlier in document order than the context node.
Ex1: //*[@id='main']/preceding-sibling::*
RESULT -à it will selects all element nodes before the current node of same level

Ex2: //*[@id='main']/preceding-sibling::div
RESULT -à it will selects all div nodes before the current node of same level

Ex:3: //*[@id='main']/preceding-sibling::div[position()>2]
Result à it will select all div nodes before the current node which is 2ndposition on wards

Attribute
Selects the attribute of the context node
Ex:1: //*[@id='viewport']/attribute::*
Selects the

Ex:2//*[@id='viewport']/attribute::class
Selects the

Ex:3
//div/attribute::class
Selects the

Ex: //div/a[text()="Gmail"]
Result àThis will find a link that has text ="Gmail"

Self
//*[@id='viewport']/self::*
Result àSelf returns the current node.

Few more examples:
Ex: //*[@id='viewport']/div[count(*)>0]àResult it will select all div node of the current node

Ex: //*[@id='viewport']/div[last()-3]
/*[last ()-3] describes the 4th upper node (div [2]) from last node.
Ex //div[@class='s2h6df']/child::div[position()=1]
Selects the first child of the context node

Ex: //div[@class='s2h6df']/child::div[position()=last()]
Selects the first child of the context node

Ex: //div[@class='s2h6df']/child::div[position()=last()-1]
Selects the last but one child of the context node

Ex: //div[@class='s2h6df']/child::div[position()>1]
Selects the all child node except first context node

The parent axis contains only a maximum of one node. The parent node may be either the root node or an element node.the parent axis contains one node.
1) //*[@class='zOB73']/parent::*
Result à it will selects parent of the @class='zOB73' node
1) //*[@class='zOB73']/parent::div[1]àit will select first div node
2) //*[@class='zOB73']/parent::div à it will select all div nodes
Following
Following axis contains all nodes in the same document as the context node that are after the context node in document order.
Ex:1
//*[@class='zOB73']/following::div
Result à it will selects only div nodes after the current node
Ex2://*[@class='s2h6df']/following::*
Result -à it will selects all element nodes after the current node
Following Sibling
The following-sibling axis selects those nodes that are siblings of the context node (that
is, the context node and its sibling nodes share a parent node) and which occur later in
document order than the context node.
Ex:1//*[@class='gb_T']/following-sibling::div
Ex:1//*[@class='gb_T']/following-sibling::*
Ancestor
Selects all ancestors (parent, grandparent, etc.) of the current node
1) //*[@id='cst']/ancestor::div[@id='viewport']
2) //*[@id='searchform']/ancestor::div
3) //*[@id='cst']/ancestor::*
4) //*[@id='logocont']/ancestor::div[position()=3]
5) //*[@id='logocont']/ancestor-or-self::div
Ancestor-or-self lets you select any ancestors [e.g., Parent and Grandparent] of the current node including the current node.
Descendant
Selects all descendants (children, grandchildren, etc.) of the current node
1) //*[@id='viewport']/descendant::div
Result à it will display all div nodes from current node
1) //*[@class='s2h6df']/descendant::div[@class='HKjQUb']
Result à it will display specific node from current node
2) //*[@id='viewport']/descendant-or-self::div
Descendant-or-self lets you select all descendants [e.g., Children and Grandchildren] of the current node including the current node.
3) //*[@id='viewport']/descendant-or-self::div[3]
Resultà it will select 3rd position from then current node
Child
Selects all class nodes that are children of the current nodebecause below example we are selected class node
//*[@id='viewport']/child::div
Result à it will display all child nodes of current node specific to div node only
Note: other than div is there It will not select
//*[@id='viewport']/child::div[@id='gac_scont']
Result à it will display specific node from current node
Child :: *
//*[@id='viewport']/child::*
Result àSelects all element children of the current node
Child::Text()
Selects all text node children of the context node
Ex: //a/child::text()
Child::node()
Selects all children of the context node, whatever their node type
Note : it is very similar to child::*
Ex:1//*[@id='viewport']/child::*
Ex 2: //*[@id='viewport']/child::div[position()=2]
Result à it will select child node of div which is on 2nd position
Preceding
The preceding axis contains all nodes in the same document as the context node that are before the context node in document order.
Ex:
//*[@id='viewport']/preceding::*
Result à it will select all element nodes before the current node
Ex 2:
//*[@id='main']/preceding::div
It will select only div nodes before the current node
Preceding – position
//*[@id='main']/preceding::div[position()=1]
Result: it will select node which Is on position 1 of div
Preceding –sibling
The preceding-sibling axis selects those nodes which are siblings of the context node (that is, the context node and its sibling nodes share a parent node) and which occur earlier in document order than the context node.
Ex1: //*[@id='main']/preceding-sibling::*
RESULT -à it will selects all element nodes before the current node of same level
Ex2: //*[@id='main']/preceding-sibling::div
RESULT -à it will selects all div nodes before the current node of same level
Ex:3: //*[@id='main']/preceding-sibling::div[position()>2]
Result à it will select all div nodes before the current node which is 2ndposition on wards
Attribute
Selects the attribute of the context node
Ex:1: //*[@id='viewport']/attribute::*
Selects the
all
attributes of the context nodeEx:2//*[@id='viewport']/attribute::class
Selects the
class
attribute of the context nodeEx:3
//div/attribute::class
Selects the
class
attribute of the context nodeEx: //div/a[text()="Gmail"]
Result àThis will find a link that has text ="Gmail"
Self
//*[@id='viewport']/self::*
Result àSelf returns the current node.
Few more examples:
Ex: //*[@id='viewport']/div[count(*)>0]àResult it will select all div node of the current node
Ex: //*[@id='viewport']/div[last()-3]
/*[last ()-3] describes the 4th upper node (div [2]) from last node.
Ex //div[@class='s2h6df']/child::div[position()=1]
Selects the first child of the context node
Ex: //div[@class='s2h6df']/child::div[position()=last()]
Selects the first child of the context node
Ex: //div[@class='s2h6df']/child::div[position()=last()-1]
Selects the last but one child of the context node
Ex: //div[@class='s2h6df']/child::div[position()>1]
Selects the all child node except first context node
Parent
The parent axis contains only a maximum of one node. The parent node may be either the root node or an element node.the parent axis contains one node.
1) //*[@class='zOB73']/parent::*
Result à it will selects parent of the @class='zOB73' node
1) //*[@class='zOB73']/parent::div[1]àit will select first div node
2) //*[@class='zOB73']/parent::div à it will select all div nodes
Following
Following axis contains all nodes in the same document as the context node that are after the context node in document order.
Ex:1
//*[@class='zOB73']/following::div
Result à it will selects only div nodes after the current node
Ex2://*[@class='s2h6df']/following::*
Result -à it will selects all element nodes after the current node
Following Sibling
The following-sibling axis selects those nodes that are siblings of the context node (that
is, the context node and its sibling nodes share a parent node) and which occur later in
document order than the context node.
Ex:1//*[@class='gb_T']/following-sibling::div
Ex:1//*[@class='gb_T']/following-sibling::*
Ancestor
Selects all ancestors (parent, grandparent, etc.) of the current node
1) //*[@id='cst']/ancestor::div[@id='viewport']
2) //*[@id='searchform']/ancestor::div
3) //*[@id='cst']/ancestor::*
4) //*[@id='logocont']/ancestor::div[position()=3]
5) //*[@id='logocont']/ancestor-or-self::div
Ancestor-or-self lets you select any ancestors [e.g., Parent and Grandparent] of the current node including the current node.
Descendant
Selects all descendants (children, grandchildren, etc.) of the current node
1) //*[@id='viewport']/descendant::div
Result à it will display all div nodes from current node
1) //*[@class='s2h6df']/descendant::div[@class='HKjQUb']
Result à it will display specific node from current node
2) //*[@id='viewport']/descendant-or-self::div
Descendant-or-self lets you select all descendants [e.g., Children and Grandchildren] of the current node including the current node.
3) //*[@id='viewport']/descendant-or-self::div[3]
Resultà it will select 3rd position from then current node
Child
Selects all class nodes that are children of the current nodebecause below example we are selected class node
//*[@id='viewport']/child::div
Result à it will display all child nodes of current node specific to div node only
Note: other than div is there It will not select
//*[@id='viewport']/child::div[@id='gac_scont']
Result à it will display specific node from current node
Child :: *
//*[@id='viewport']/child::*
Result àSelects all element children of the current node
Child::Text()
Selects all text node children of the context node
Ex: //a/child::text()
Child::node()
Selects all children of the context node, whatever their node type
Note : it is very similar to child::*
Ex:1//*[@id='viewport']/child::*
Ex 2: //*[@id='viewport']/child::div[position()=2]
Result à it will select child node of div which is on 2nd position
Preceding
The preceding axis contains all nodes in the same document as the context node that are before the context node in document order.
Ex:
//*[@id='viewport']/preceding::*
Result à it will select all element nodes before the current node
Ex 2:
//*[@id='main']/preceding::div
It will select only div nodes before the current node
Preceding – position
//*[@id='main']/preceding::div[position()=1]
Result: it will select node which Is on position 1 of div
Preceding –sibling
The preceding-sibling axis selects those nodes which are siblings of the context node (that is, the context node and its sibling nodes share a parent node) and which occur earlier in document order than the context node.
Ex1: //*[@id='main']/preceding-sibling::*
RESULT -à it will selects all element nodes before the current node of same level
Ex2: //*[@id='main']/preceding-sibling::div
RESULT -à it will selects all div nodes before the current node of same level
Ex:3: //*[@id='main']/preceding-sibling::div[position()>2]
Result à it will select all div nodes before the current node which is 2ndposition on wards
Attribute
Selects the attribute of the context node
Ex:1: //*[@id='viewport']/attribute::*
Selects the
all
attributes of the context nodeEx:2//*[@id='viewport']/attribute::class
Selects the
class
attribute of the context nodeEx:3
//div/attribute::class
Selects the
class
attribute of the context nodeEx: //div/a[text()="Gmail"]
Result àThis will find a link that has text ="Gmail"
Self
//*[@id='viewport']/self::*
Result àSelf returns the current node.
Few more examples:
Ex: //*[@id='viewport']/div[count(*)>0]àResult it will select all div node of the current node
Ex: //*[@id='viewport']/div[last()-3]
/*[last ()-3] describes the 4th upper node (div [2]) from last node.
Ex //div[@class='s2h6df']/child::div[position()=1]
Selects the first child of the context node
Ex: //div[@class='s2h6df']/child::div[position()=last()]
Selects the first child of the context node
Ex: //div[@class='s2h6df']/child::div[position()=last()-1]
Selects the last but one child of the context node
Ex: //div[@class='s2h6df']/child::div[position()>1]
Selects the all child node except first context node
Comments
Post a Comment