Reputation: 695
Can someone please tell me if I have interpreted the following XPath correctly:
driver.find_elements_by_xpath ("//span[contains(., 'Cardiovascular')]/parent::*/parent::*/descendant-or-self::node()/a/span"
More specifically, can someone please tell me what /parent::*/parent means? What /parent::/descendant-or-self::node() means? why do we have node() as a function there
Upvotes: 1
Views: 91
Reputation: 111726
Michael Kay already explained what the XPath selects. Here are the answers to your additional questions:
More specifically, can someone please tell me what
/parent::*/parent
[sic] means?
parent::*
means to select the parent element (*
matches elements of any name) of the context node.parent::*/parent::*
means to select the grandparent element of the context node.What
/parent::/descendant-or-self::node()
[sic] means?why do we have node() as a function there
parent::*
means (and note that you forgot the *
).descendant-or-self::node()
is the same as .//node()
; it selects the context node and all of its descendants. Here, node()
is not a function but rather a node test. Had it been element()
, it would select only elements; comment()
, only comments; etc.Upvotes: 1
Reputation: 163625
Almost.
Look for the span
tags that have "cardiovascular" as part of their text; find their grandparent elements; then within these grandparent elements, find all span
elements that have an a
element as their parent.
Upvotes: 1