fix(parser): change the default threshold and add warning

This commit is contained in:
Karim shoair
2026-05-02 19:58:53 +03:00
parent ea7b4bddd3
commit 333b6de0b5
+9 -5
View File
@@ -519,7 +519,7 @@ class Selector(SelectorsGeneration):
def relocate( def relocate(
self, self,
element: Union[Dict, HtmlElement, "Selector"], element: Union[Dict, HtmlElement, "Selector"],
percentage: int = 0, percentage: int = 40,
selector_type: bool = False, selector_type: bool = False,
) -> Union[List[HtmlElement], "Selectors"]: ) -> Union[List[HtmlElement], "Selectors"]:
"""This function will search again for the element in the page tree, used automatically on page structure change """This function will search again for the element in the page tree, used automatically on page structure change
@@ -559,6 +559,10 @@ class Selector(SelectorsGeneration):
if not selector_type: if not selector_type:
return score_table[highest_probability] return score_table[highest_probability]
return self.__elements_convertor(score_table[highest_probability]) return self.__elements_convertor(score_table[highest_probability])
log.warning(
f"Adaptive relocation found no element above the {percentage}% threshold "
f"(top score: {highest_probability}%). Lower `percentage` if this is the right element."
)
return [] return []
def css( def css(
@@ -567,7 +571,7 @@ class Selector(SelectorsGeneration):
identifier: str = "", identifier: str = "",
adaptive: bool = False, adaptive: bool = False,
auto_save: bool = False, auto_save: bool = False,
percentage: int = 0, percentage: int = 40,
) -> "Selectors": ) -> "Selectors":
"""Search the current tree with CSS3 selectors """Search the current tree with CSS3 selectors
@@ -627,7 +631,7 @@ class Selector(SelectorsGeneration):
identifier: str = "", identifier: str = "",
adaptive: bool = False, adaptive: bool = False,
auto_save: bool = False, auto_save: bool = False,
percentage: int = 0, percentage: int = 40,
**kwargs: Any, **kwargs: Any,
) -> "Selectors": ) -> "Selectors":
"""Search the current tree with XPath selectors """Search the current tree with XPath selectors
@@ -1220,7 +1224,7 @@ class Selectors(List[Selector]):
selector: str, selector: str,
identifier: str = "", identifier: str = "",
auto_save: bool = False, auto_save: bool = False,
percentage: int = 0, percentage: int = 40,
**kwargs: Any, **kwargs: Any,
) -> "Selectors": ) -> "Selectors":
""" """
@@ -1251,7 +1255,7 @@ class Selectors(List[Selector]):
selector: str, selector: str,
identifier: str = "", identifier: str = "",
auto_save: bool = False, auto_save: bool = False,
percentage: int = 0, percentage: int = 40,
) -> "Selectors": ) -> "Selectors":
""" """
Call the ``.css()`` method for each element in this list and return Call the ``.css()`` method for each element in this list and return