修复小问题

This commit is contained in:
g1879 2023-12-21 16:28:41 +08:00
parent 71dfe3037c
commit 4de95e6354
3 changed files with 9 additions and 13 deletions

View File

@ -68,14 +68,13 @@ class BaseElement(BaseParser):
def _ele(self, loc_or_str, timeout=None, single=True, relative=False, raise_err=None, method=None): def _ele(self, loc_or_str, timeout=None, single=True, relative=False, raise_err=None, method=None):
r = self._find_elements(loc_or_str, timeout=timeout, single=single, relative=relative, raise_err=raise_err) r = self._find_elements(loc_or_str, timeout=timeout, single=single, relative=relative, raise_err=raise_err)
if not single: if r or isinstance(r, list):
return r return r
if isinstance(r, NoneElement): if Settings.raise_when_ele_not_found or raise_err is True:
if Settings.raise_when_ele_not_found or raise_err is True: raise ElementNotFoundError(None, method, {'loc_or_str': loc_or_str})
raise ElementNotFoundError(None, method, {'loc_or_str': loc_or_str})
else: r.method = method
r.method = method r.args = {'loc_or_str': loc_or_str}
r.args = {'loc_or_str': loc_or_str}
return r return r
@abstractmethod @abstractmethod

View File

@ -404,7 +404,7 @@ def translate_loc(loc):
elif loc_0 == By.CLASS_NAME: elif loc_0 == By.CLASS_NAME:
loc_str = f'//*[@class="{loc[1]}"]' loc_str = f'//*[@class="{loc[1]}"]'
elif loc_0 == By.PARTIAL_LINK_TEXT: elif loc_0 == By.LINK_TEXT:
loc_str = f'//a[text()="{loc[1]}"]' loc_str = f'//a[text()="{loc[1]}"]'
elif loc_0 == By.NAME: elif loc_0 == By.NAME:
@ -446,7 +446,7 @@ def translate_css_loc(loc):
elif loc_0 == By.CLASS_NAME: elif loc_0 == By.CLASS_NAME:
loc_str = f'.{css_trans(loc[1])}' loc_str = f'.{css_trans(loc[1])}'
elif loc_0 == By.PARTIAL_LINK_TEXT: elif loc_0 == By.LINK_TEXT:
loc_by = By.XPATH loc_by = By.XPATH
loc_str = f'//a[text()="{css_trans(loc[1])}"]' loc_str = f'//a[text()="{css_trans(loc[1])}"]'
@ -463,9 +463,6 @@ def translate_css_loc(loc):
else: else:
raise ValueError('无法识别的定位符。') raise ValueError('无法识别的定位符。')
if loc_by == By.CSS_SELECTOR:
pass
return loc_by, loc_str return loc_by, loc_str

View File

@ -267,7 +267,7 @@ def raise_error(result, ignore=None):
'No node with given id found', 'Node with given id does not belong to the document', 'No node with given id found', 'Node with given id does not belong to the document',
'No node found for given backend id'): 'No node found for given backend id'):
r = ElementLostError() r = ElementLostError()
elif error == ('tab closed', 'No target with given id found'): elif error in ('tab closed', 'No target with given id found'):
r = PageClosedError() r = PageClosedError()
elif error == 'timeout': elif error == 'timeout':
r = TimeoutError(f'超时。\n错误:{result["error"]}\nmethod{result["method"]}\nargs{result["args"]}\n' r = TimeoutError(f'超时。\n错误:{result["error"]}\nmethod{result["method"]}\nargs{result["args"]}\n'