This commit is contained in:
g1879 2020-08-08 01:05:19 +08:00
parent ddbe20f7a8
commit 1c9bc8dd24
4 changed files with 9 additions and 9 deletions

View File

@ -120,7 +120,7 @@ def get_loc_from_str(loc: str) -> tuple:
return loc_by, loc_str
def _make_xpath_str(tag: str, arg: str, val: str, mode: str = 'fuzzy'):
def _make_xpath_str(tag: str, arg: str, val: str, mode: str = 'fuzzy') -> str:
"""生成xpath语句"""
tag_name = '' if tag == '*' else f'name()="{tag}" and '
if mode == 'exact':
@ -129,7 +129,7 @@ def _make_xpath_str(tag: str, arg: str, val: str, mode: str = 'fuzzy'):
return f"//*[{tag_name}contains({arg},{_make_search_str(val)})]"
def _make_search_str(search_str: str):
def _make_search_str(search_str: str) -> str:
""""转义,不知何故不能直接用\""""
parts = search_str.split('"')
parts_num = len(parts)
@ -141,7 +141,7 @@ def _make_search_str(search_str: str):
return search_str
def translate_loc_to_xpath(loc):
def translate_loc_to_xpath(loc) -> tuple:
"""把By类型转为xpath或css selector"""
loc_by = 'xpath'
loc_str = None
@ -185,7 +185,7 @@ def avoid_duplicate_name(folder_path: str, file_name: str) -> str:
return file_name
def clean_folder(folder_path: str, ignore: list = None):
def clean_folder(folder_path: str, ignore: list = None) -> None:
"""清空一个文件夹除了ignore里的文件和文件夹
:param folder_path: 要清空的文件夹路径
:param ignore: 忽略列表

View File

@ -155,7 +155,7 @@ class DriverElement(DrissionElement):
if isinstance(loc_or_str, str):
loc_or_str = get_loc_from_str(loc_or_str)
elif isinstance(loc_or_str, tuple) and len(loc_or_str) == 2:
loc_or_str = translate_loc_to_xpath(loc_or_str)
pass
else:
raise ValueError('Argument loc_or_str can only be tuple or str.')

View File

@ -110,7 +110,7 @@ class DriverPage(object):
if isinstance(loc_or_ele, str):
loc_or_ele = get_loc_from_str(loc_or_ele)
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
loc_or_ele = translate_loc_to_xpath(loc_or_ele)
pass
elif isinstance(loc_or_ele, DriverElement):
return loc_or_ele
elif isinstance(loc_or_ele, WebElement):

View File

@ -97,16 +97,16 @@ class SessionPage(object):
:return: SessionElement对象
"""
if isinstance(loc_or_ele, str):
loc = get_loc_from_str(loc_or_ele)
loc_or_ele = get_loc_from_str(loc_or_ele)
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
loc = translate_loc_to_xpath(loc_or_ele)
loc_or_ele = translate_loc_to_xpath(loc_or_ele)
elif isinstance(loc_or_ele, SessionElement):
return loc_or_ele
elif isinstance(loc_or_ele, Element):
return SessionElement(loc_or_ele)
else:
raise ValueError('Argument loc_or_str can only be tuple, str, SessionElement, Element.')
return execute_session_find(self.response.html, loc, mode, show_errmsg)
return execute_session_find(self.response.html, loc_or_ele, mode, show_errmsg)
def eles(self, loc_or_str: Union[tuple, str], show_errmsg: bool = False) -> List[SessionElement]:
"""返回页面中所有符合条件的元素 \n