Improve error-handling for "by"-selection

This commit is contained in:
Michael Mintz 2024-08-06 23:15:38 -04:00
parent af8e11dd50
commit b0909b3bec
1 changed files with 7 additions and 0 deletions

View File

@ -114,6 +114,13 @@ def recalculate_selector(selector, by, xp_ok=True):
by = By.XPATH by = By.XPATH
if by == "": if by == "":
by = By.CSS_SELECTOR by = By.CSS_SELECTOR
if not is_valid_by(by):
valid_by_options = [
"css selector", "link text", "partial link text",
"name", "xpath", "id", "tag name", "class name",
]
msg = "Choose a `by` from: %s." % valid_by_options
raise Exception('Invalid `by`: "%s"\n%s' % (by, msg))
return (selector, by) return (selector, by)