Normalizing the element type
This is where we will write a method to normalize all the explicit strings. Here, link
becomes //a
, button
becomes //button
, and so on. Your framework can continue to expand with many other element types as needed. The following function, normalizeElementType()
, will take a plain English description of the element and translate it into a common xPath
equivalent. Note that field
and input
become the same class, while an empty class description becomes a locator for all elements:
function normalizeElementType(elementType: string) { // Pessimistic: return all matches if the type is unknown let elementText = "//*" switch (elementType) { case "link": elementText = "//a"; break; case "button": elementText = "/...