Python ElementTree findall: "SyntaxError: cannot use absolute path on element", "invalid predicate" for [@x=1] and text(); if elem: is False for leaf elements
ElementTree supports only a small XPath subset with generic errors: findall('/a/b') raises SyntaxError: cannot use absolute path on element (use './b'), b[@x=1] raises SyntaxError: invalid predicate (values must be quoted: [@x='1']), b[text()='v'] also raises invalid predicate (use [.='v']), position() raises SyntaxError: unsupported function, and b[0] raises XPath position >= 1 expected. Separately, an Element with no children is falsy, so if root.find('b'): skips elements that exist; 3.12+ emits DeprecationWarning: Testing an element's truth value will always return True in future versions (3.11 is silent). Fix: use the supported subset (or lxml for full XPath), and always test with is not None or len(elem). Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.