fix: prevent duplicate ID segments in full-path selector generation
When generating full-path CSS/XPath selectors, elements with id attributes had their selector appended twice — once in the id branch (line 30) and again unconditionally (line 50). This produced selectors like 'body > #main > #main > #target > #target' instead of the correct 'body > #main > #target'. Move the append into the else branch so it only fires for elements without an id (elements with id already append in the if branch). Includes 2 regression tests.
This commit is contained in:
@@ -47,7 +47,7 @@ class SelectorsGeneration:
|
||||
if counter[target.tag] > 1:
|
||||
part += f":nth-of-type({counter[target.tag]})" if css else f"[{counter[target.tag]}]"
|
||||
|
||||
selectorPath.append(part)
|
||||
selectorPath.append(part)
|
||||
target = target.parent
|
||||
if target is None or target.tag == "html":
|
||||
return " > ".join(reversed(selectorPath)) if css else "//" + "/".join(reversed(selectorPath))
|
||||
|
||||
Reference in New Issue
Block a user