Better logic for css_first and xpath_first

This commit is contained in:
Karim shoair
2024-11-06 22:14:33 +02:00
parent 5e848ef046
commit 6b40af426f
+4 -6
View File
@@ -416,9 +416,8 @@ class Adaptor(SelectorsGeneration):
:return: List as :class:`Adaptors` :return: List as :class:`Adaptors`
""" """
try: for element in self.css(selector, identifier, auto_match, auto_save, percentage):
return self.css(selector, identifier, auto_match, auto_save, percentage)[0] return element
except (IndexError, TypeError,):
return None return None
def xpath_first(self, selector: str, identifier: str = '', def xpath_first(self, selector: str, identifier: str = '',
@@ -443,9 +442,8 @@ class Adaptor(SelectorsGeneration):
:return: List as :class:`Adaptors` :return: List as :class:`Adaptors`
""" """
try: for element in self.xpath(selector, identifier, auto_match, auto_save, percentage, **kwargs):
return self.xpath(selector, identifier, auto_match, auto_save, percentage, **kwargs)[0] return element
except (IndexError, TypeError,):
return None return None
def css(self, selector: str, identifier: str = '', def css(self, selector: str, identifier: str = '',