Note| Text in Blue [#PYTHON] and Orange [#JAVA] can be edited or mentioned important for the entire blog. All the posts are practically done by me.
The location path can be either
1| Absolute location path
- Starts with (/)
e.g., /step/step/..
2| Relative location path
- Does not starts with (/)
e.g., step/step/..
Here, each and every step consists of
1| axis
2| node-test
3| zero or predicates
axisname::nodetest[predicate]
Axis name
ancestor
ancestor-or-self
attribute (@)
child (/)
descendant (//)
descendant-or-self
following
following-sibling
namespace
parent(../)
preceding
preceding-sibling
self (./)
child (/)
descendant (//)
descendant-or-self
following
following-sibling
namespace
parent(../)
preceding
preceding-sibling
self (./)
The Xpath Axes mentioned below are based on the following URL, http://docs.python.org/2/library/re.html
ancestor
Ancestor lets you select any ancestors [e.g., Parent and Grandparent] of the current node.
//*[@id='regular-expression-syntax']/ancestor::div[5]/div[2]
//*[@id='regular-expression-syntax']/ancestor::*
//*[@class='sphinxsidebarwrapper']/attribute::*
//*[@id='sidebarbutton']/attribute::title
//*[@class='this-page-menu']/descendant::*
//*[@class='this-page-menu']/descendant::li[2]
//*[@class='documentwrapper']/descendant::div[position()=3]
//*[@class='clearer']/following::*
//*[@class='related']/following-sibling::*
//*[@class='related']/following-sibling::div[3]
TBD
//*[@class='sphinxsidebar']/parent::node()
//*[@class='bodywrapper']/parent::*
//*[@class='bodywrapper']/parent::div[1]
//*[@class='bodywrapper']/parent::div
//*[@class='bodywrapper']/preceding::*
//*[@class='footer']/preceding-sibling::*
//*[@class='footer']/preceding-sibling::div[2]
//*[@class='footer']/self::*
//*[@class='footer']/self::div
Note| Refer URL for more details
//*[@id='regular-expression-syntax']/ancestor::div[5]/div[2]
//*[@id='regular-expression-syntax']/ancestor::*
ancestor-or-self
Ancestor-or-self lets you select any ancestors [e.g., Parent and Grandparent] of the current node including the current node.
//*[@id='regular-expression-syntax']/ancestor-or-self::div[1]
//*[@id='regular-expression-syntax']/ancestor-or-self::*
//*[@id='regular-expression-syntax']/ancestor-or-self::div[1]
//*[@id='regular-expression-syntax']/ancestor-or-self::*
attribute
Attribute returns all the attributes in the current node.//*[@class='sphinxsidebarwrapper']/attribute::*
//*[@id='sidebarbutton']/attribute::title
child
Child returns all the children in the current node.
//*[@class='sphinxsidebarwrapper']/child::*
//*//child::h3
//*[@class='sphinxsidebarwrapper']/child::*
//*//child::h3
descendant
Descendant lets you select all descendants [e.g., Children and Grandchildren] of the current node.//*[@class='this-page-menu']/descendant::*
//*[@class='this-page-menu']/descendant::li[2]
//*[@class='documentwrapper']/descendant::div[position()=3]
descendant-or-self
Descendant-or-self lets you select all descendants [e.g., Children and Grandchildren] of the current node including the current node.
//*[@class='this-page-menu']/descendant-or-self::*
//*[@id='searchbox']/descendant-or-self::form[@class='search']/input[2]
//*[@class='this-page-menu']/descendant-or-self::*
//*[@id='searchbox']/descendant-or-self::form[@class='search']/input[2]
following
Following returns all in the document after the closing tag of the current node.//*[@class='clearer']/following::*
following-sibling
Following-sibling returns all the sibling after the closing tag of the current node.//*[@class='related']/following-sibling::*
//*[@class='related']/following-sibling::div[3]
namespace
Namespace returns all namespace nodes in the current node.TBD
parent
Parent returns the parent of the current node.//*[@class='sphinxsidebar']/parent::node()
//*[@class='bodywrapper']/parent::*
//*[@class='bodywrapper']/parent::div[1]
//*[@class='bodywrapper']/parent::div
preceding
Preceding is a reverse of Following; Preceding returns all in the document before the current node//*[@class='bodywrapper']/preceding::*
preceding-sibling
Preceding-sibling is a reverse of Following-sibling; Preceding-sibling returns all the sibling before the current node.//*[@class='footer']/preceding-sibling::*
//*[@class='footer']/preceding-sibling::div[2]
self
Self returns the current node.//*[@class='footer']/self::*
//*[@class='footer']/self::div
Note| Refer URL for more details
It was very nice article and it is very useful to Selenium learners.We also provide Cub training software online training.
ReplyDelete