in modules/page_base.py [0:0]
def get_selector(self, name: str, labels=[]) -> list:
"""
Given a key for a self.elements dict entry, return the Selenium selector tuple.
If there are items in `labels`, replace instances of {.*} in the "selectorData"
with items from `labels`, in the order they are given. (Think Rust format macros.)
...
Arguments
---------
name: str
The key of the entry in self.elements, parsed from the elements JSON
labels: list[str]
Strings that replace instances of {.*} in the "selectorData" subentry of
self.elements[name]
Returns
-------
list
The Selenium selector tuple (as a list)
"""
logging.info(f"Get selector for {name}...")
element_data = self.elements[name]
selector = [
STRATEGY_MAP[element_data["strategy"]],
element_data["selectorData"],
]
if not labels:
logging.info("Returned selector.")
return selector
braces = re.compile(r"(\{.*?\})")
match = braces.findall(selector[1])
for i in range(len(labels)):
logging.info(f"Replace {match[i]} with {labels[i]}")
selector[1] = selector[1].replace(match[i], labels[i], 1)
logging.info("Returned selector.")
return selector