xpathaxestask





XPath Axes Practice – From Basics to Advanced


XPath Axes Practice Page – Basics to Advanced

Use this page to practice XPath axes concepts — from basic to advanced. Each section includes practical **tasks for students** to try writing XPath expressions.

1️⃣ Basic Axes: child:: and descendant::

Task: Write XPath to select all child li of main ul.
Task: Write XPath to select **descendant** li of the “Courses” item.

2️⃣ parent:: and ancestor::


Task: Write XPath to select the parent of the input field.
Task: Write XPath to select the ancestor div of the label.

3️⃣ Sibling Axes: following-sibling:: and preceding-sibling::



Password must be at least 8 characters.
Task: Write XPath to select the small element using following-sibling.
Task: Write XPath to select label using preceding-sibling from input.

4️⃣ following:: and preceding::

This is paragraph 1.

This is paragraph 2.

This is paragraph 3.

Task: Select the 3rd paragraph using following:: from paragraph 1.
Task: Select the 1st paragraph using preceding:: from paragraph 3.

5️⃣ self:: and descendant::

Course Information

Instructor: John Doe

Duration: 6 weeks

Task: Select self h3 element.
Task: Select all descendant p elements inside div.card.

6️⃣ Advanced Table Navigation (Combining Axes)

Student Name Course Status Action
Alice Manual Testing Completed View
Bob Automation Testing In Progress View
Charlie Manual Testing In Progress View
Task: Select “View” link of **Alice** using following-sibling axis.
Task: Select “Manual Testing” course cell using preceding-sibling axis from “In Progress” status.
Task: Select “In Progress” status using following axis from “Bob”.

Final Note

Use browser tools (Inspect → Elements → Copy XPath or try writing your own XPath) to practice.

Challenge: Try combining multiple axes in one XPath expression!