Architecture Overview
XPathy follows a layered architecture for building locators. Each starting point returns a builder object that knows how to handle that context:
.byText()→ switches context to element text, allowing operations like.equals(),.contains(),.startsWith().byAttribute(attribute)→ switches context to a specific attribute, enabling methods such as.equals(),.contains(),.startsWith(),.greaterThan(),.lessThan().byNumber()→ converts inner text into a number, making numeric methods like.greaterThan(),.lessThan(),.between()available.byStyle(styleAttribute)→ inspects inline CSS properties inside thestyleattribute, and supports.equals(),.haveIt()
How Methods are Chained
When you call .equals(), .contains(), .startsWith(),
etc., you are finalizing the condition on the selected context.
Example 1: Attribute Context
Code
XPathy locator = div.byAttribute(id).equals("header");
Flow:
divsets the base tag.byAttribute(id)selects theidattribute.equals("header")finalizes the expression as//div[@id='header']
Example 2: Text Context
Code
XPathy locator = h2.byText().startsWith("Title");
Flow:
h2sets the base tag.byText()switches to the text node.startsWith("Title")produces//h2[starts-with(text(),'Title')]
Key Insight: This consistent flow applies to all contexts.
You always begin with a tag or attribute, select the context with
.byText(),
.byAttribute(), .byNumber(), or .byStyle(), then
finalize with methods like .equals(), .contains(),
.startsWith(), .greaterThan(), or .between().
Complete Flow Examples
Number Context Flow
Code
XPathy locator = td.byNumber().greaterThan(100);
Flow:
tdsets the base tag.byNumber()converts text content to number context.greaterThan(100)creates condition//td[number(text()) > 100]
Style Context Flow
Code
XPathy locator = div.byStyle(backgroundColor).equals("#fff");
Flow:
divsets the base tag.byStyle(backgroundColor)switches to inline style context.equals("#fff")checks for background color value
Result: The resulting
XPathy object can be converted to a
Selenium By object with .getLocator(), making it directly usable
in your test automation scripts.