fix: emit valid XPath node test for ID elements in full-path mode
Address review feedback: In full-path XPath generation, elements with IDs were producing bare predicates like `[@id='x']` which creates invalid XPath steps like `//body/[@id='main']`. Now emits `*[@id='x']` for full-path mode (e.g. `//body/*[@id='main']/*[@id='target']`). Short-path XPath mode unchanged — still uses `//*[@id='x']` prefix. Also added XPath evaluation assertion to the regression test to verify the generated selector actually selects the correct element. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -342,6 +342,11 @@ def test_full_path_selector_no_duplicate_ids():
|
||||
assert len(result) == 1
|
||||
assert result.first.text == "Hello"
|
||||
|
||||
# The generated XPath selector should also select the correct element
|
||||
result = page.xpath(xpath_full)
|
||||
assert len(result) == 1, f"XPath '{xpath_full}' selected {len(result)} elements, expected 1"
|
||||
assert result.first.text == "Hello"
|
||||
|
||||
|
||||
def test_full_path_selector_mixed_id_and_no_id():
|
||||
"""Test full path selectors with a mix of elements with and without ids"""
|
||||
|
||||
Reference in New Issue
Block a user