完善注释,修正文本错误

This commit is contained in:
g1879 2020-08-13 11:44:08 +08:00
parent 16847f829d
commit cff95304f9

View File

@ -147,7 +147,7 @@ class DriverPage(object):
:param show_errmsg: 出现异常时是否打印信息
:return: DriverElement对象组成的列表
"""
if not isinstance(loc_or_str, tuple) and not isinstance(loc_or_str, str):
if not isinstance(loc_or_str, (tuple, str)):
raise TypeError('Type of loc_or_str can only be tuple or str.')
return self.ele(loc_or_str, mode='all', timeout=timeout, show_errmsg=show_errmsg)
@ -220,28 +220,28 @@ class DriverPage(object):
"""
return self.driver.execute_script(script)
@property
def tabs_conut(self) -> int:
@property
def tabs_count(self) -> int:
"""返回标签页数量"""
try:
return len(self.driver.window_handles)
except:
return 0
@property
@property
def tab_handles(self) -> list:
"""返回所有标签页handle列表"""
return self.driver.window_handles
"""返回所有标签页handle列表"""
return self.driver.window_handles
@property
@property
def current_tab_num(self) -> int:
"""返回当前标签页序号"""
return self.driver.window_handles.index(self.driver.current_window_handle)
@property
def current_tab_handle(safe) -> str:
"""返回当前标签页handle"""
return self.driver.current_window_handle
@property
def current_tab_handle(self) -> str:
"""返回当前标签页handle"""
return self.driver.current_window_handle
def create_tab(self, url: str = '') -> None:
"""新建并定位到一个标签页,该标签页在最后面 \n
@ -255,7 +255,7 @@ class DriverPage(object):
def close_current_tab(self) -> None:
"""关闭当前标签页"""
self.driver.close()
if self.tabs_conut:
if self.tabs_count:
self.to_tab(0)
def close_other_tabs(self, num_or_handle: Union[int, str, None] = None) -> None:
@ -263,15 +263,20 @@ class DriverPage(object):
:param num_or_handle: 要保留的标签页序号或handle序号第一个为0最后为-1
:return: None
"""
tabs = self.driver.window_handles # 获得所有标签页权柄
if num_or_handle is None:
page_handle = self.current_tab_handle
elif isinstance(num_or_handle, int):
page_handle = tabs[num_or_handle]
elif isinstance(num_or_handle, str):
page_handle = num_or_handle
try:
tab = int(num_or_handle)
except (ValueError, TypeError):
tab = num_or_handle
tabs = self.driver.window_handles
if tab is None:
page_handle = self.current_tab_handle
elif isinstance(tab, int):
page_handle = tabs[tab]
elif isinstance(tab, str):
page_handle = tab
else:
raise TypeError('Argument num_or_handle must be int or str.')
raise TypeError('Argument num_or_handle can only be int or str.')
for i in tabs: # 遍历所有标签页,关闭非保留的
if i != page_handle:
@ -284,21 +289,25 @@ class DriverPage(object):
:param num_or_handle: 标签页序号或handle字符串序号第一个为0最后为-1
:return: None
"""
tab = self.driver.window_handles[num_or_handle] if isinstance(num_or_handle, int) else num_or_handle
try:
tab = int(num_or_handle)
except (ValueError, TypeError):
tab = num_or_handle
tab = self.driver.window_handles[tab] if isinstance(tab, int) else tab
self.driver.switch_to.window(tab)
def to_iframe(self, loc_or_ele: Union[int, str, tuple, WebElement, DriverElement] = 'main') -> None:
"""跳转到iframe \n
可接收iframe序号(0开始)id或name查询字符串loc元组WebElement对象DriverElement对象 \n
传入'main'跳到最高层传入'parent'跳到上一层 \n
示例 \n
to_iframe('tag:iframe') - 通过传入iframe的查询字符串定位 \n
to_iframe('iframe_id') - 通过iframe的id属性定位 \n
to_iframe('iframe_name') - 通过iframe的name属性定位 \n
to_iframe(iframe_element) - 通过传入元素对象定位 \n
to_iframe(0) - 通过iframe的序号定位 \n
to_iframe('main') - 跳到最高层 \n
to_iframe('parent') - 跳到上一层 \n
"""跳转到iframe \n
可接收iframe序号(0开始)id或name查询字符串loc元组WebElement对象DriverElement对象 \n
传入'main'跳到最高层传入'parent'跳到上一层 \n
示例 \n
to_iframe('tag:iframe') - 通过传入iframe的查询字符串定位 \n
to_iframe('iframe_id') - 通过iframe的id属性定位 \n
to_iframe('iframe_name') - 通过iframe的name属性定位 \n
to_iframe(iframe_element) - 通过传入元素对象定位 \n
to_iframe(0) - 通过iframe的序号定位 \n
to_iframe('main') - 跳到最高层 \n
to_iframe('parent') - 跳到上一层 \n
:param loc_or_ele: iframe的定位信息
:return: None
"""