Advanced XPath and CSS Locator Strategies
Module objective: Learn how to choose stable locators in real-world UI. Each task asks you to find one exact element and click it.
Basic Locator Strategies
What to do: Use one direct locator type per row (id, name, class, tagName, linkText, partialLinkText) and click only the target element.
Expected result: Each row chip changes to Passed after the correct target click.
- By
idPending - By
namePending - By
classPending - By
tagNamePendingIgnore this - By
linkTextPending - By
partialLinkTextPending
Relative XPath Functions
What to do: Use the exact XPath function requested for each row (text(), contains(), starts-with(), grouped index, combo predicates, and multi-attribute predicates).
Expected result: Correct target click sets the corresponding chip to Passed.
- Use
text()Pending - Use
contains()Pending - Use
starts-with()Pending - Grouping/Capture style with parentheses (pick 2nd match)Pending
- Combination of functions:
contains(text())+starts-with(@id)Pending - Multiple attributes in XPath predicatePending
XPath Axes
What to do: Start from nearby anchor elements and traverse using requested axes (child, parent, ancestor, sibling, forward, and backward traversal).
Expected result: Each axis task marks Passed only when the right target is clicked.
- Axis:
child::Pending - Axis:
parent::PendingAnchor - Axis:
ancestor::PendingLeaf
- Axis:
following-sibling::Pending - Forward traversing:
following::PendingGap - Backward traversing:
preceding::PendingAnchor Node - Sibling traversal both sidesPending
Relative CSS Selectors
What to do: Use CSS selector syntax for #id, .class, multiple classes, tag selector, and multi-attribute selectors.
Expected result: Each CSS row chip changes to Passed after successful target click.
- By CSS
#idPending - By CSS
.classPending - By CSS multiple classesPending
- By CSS tagName (scoped)Pending
- By CSS multiple attributesPending
CSS Attribute "Functions"
What to do: Use CSS attribute operators *= (contains) and $= (ends-with) to match partial attribute values.
Expected result: Correct target click updates each function row to Passed.
- Contains equivalent
[attr*='value']Pending - Ends-with equivalent
[attr$='value']Pending
CSS Parent/Child and Sibling Concepts
What to do: Use relationship selectors for direct child (>), descendant (space), and sibling combinators (+/~).
Expected result: All three relationship tasks show Passed when correct targets are clicked.
- Direct child selector
parent > childPending - Indirect descendant selector
parent childPending - Following sibling selector
+/ general sibling~PendingSibling Start
Completion
In Progress: completed 0 / 29 tasks.
When all 29 are done, this module is complete.