Home->Practice 11 |
||
---|---|---|
Please Follow Step 1: Read XPath Question >> | Step 2: Check HTML Source Code >> | Step3: Enter XPath Syntax in O/P Box |
Q1. Find all Preceding Paragraph Text from Div ID="seaanimal"
using Preceding axis.
Q2. Find all Preceding Paragraph Text from Div ID="elephant2"
using Preceding axis.
Q3. Find all Preceding Paragraph Text from Div ID
="femalewildanimal" using Preceding axis.
Q4. Find all Preceding Paragraph Text from Div ID
="femalewildanimal" using Preceding-sibling axis.
Q5. Find all Preceding Paragraph Text from Div ID="bitch"
using Preceding-sibling axis.
Q6. Find all Preceding Paragraph Text from Div ID="elephant2"
using Preceding-sibling axis.
Q7. Find all Preceding Paragraph Text from Div ID="seaanimal"
using Preceding-sibling axis.
Q8. Find all Preceding Paragraph Text from Div ID="elephant"
using Parent axis.
Q9. Find all Preceding Paragraph Text from Div ID="leopardess"
using Parent axis.
Q9. Find all Preceding Paragraph Text from Div ID="wildanimal"
using Parent axis.
Q10. Find all Preceding Paragraph Text from Div ID="wildanimal"
using Parent axis.
Q11. Find all Ancestor Paragraph Text from Div ID="elephant2"
using Ancestor axis.
Q12. Find all Ancestor Paragraph Text from Div ID="leopardess"
using Ancestor axis.
Q13. Find Wild Animal Paragraph Text from Div ID="elephant2"
using Ancestor axis.
<div id="animal"> <p>Animal</p> <div id="wildanimal"> <p>Wild Animal</p> <div id="malewildanimal"> <p>Male Wild Animal </p> <div id="lion"> <p>Lion</p> </div> <div id="elephant"> <p>Elephant</p> <div id="elephant1"> <p>Elephant 1</p> </div> <div id="elephant2"> <p>Elephant 2</p> </div> </div> </div> <div id="femalewildanimal"> <p>Female Wild Animal </p> <div id="lioness"> <p>Lioness</p> </div> <div id="tigeress"> <p>Tigeress</p> </div> <div id="leopardess"> <p>Leopardess</p> </div> <div id="bitch"> <p>Bitch</p> </div> </div> <div id="seaanimal"> <p>Sea Animal </p> </div> </div> </div>
Animal
Wild Animal
Male Wild Animal
Lion
Elephant
Elephant 1
Elephant 2
Female Wild Animal
Lioness
Tigeress
Leopardess
Bitch
Sea Animal
Using Preceding Axis
//input[@id = 'testdata']//preceding::input
In XPath, the "preceding" axis selects all nodes that come before the current node in document order.
Using Preceding-sibling Axis
In XPath, the "preceding-sibling" axis selects all siblings that come before the current node. The syntax is as follows:
//element[position()=1]/preceding-sibling::* or //a[text() = 'Videos']//preceding-sibling::a
Using Parent Axis
In XPath, the "parent" axis selects the parent of the current node. The syntax is as follows:
//parent::tagName or e.g //input[@id = 'text']//parent::span
Using Ancestor Axis
In XPath, the "ancestor" axis selects all ancestors of the current node, starting from the parent and going up to the root of the document. The syntax is as follows:
//div[@class='Mammal']/ancestor::div or //input[@id = 'ssd']//ancestor::td