mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
完善注释,修正文本错误
This commit is contained in:
parent
16847f829d
commit
cff95304f9
@ -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)
|
||||
|
||||
@ -221,7 +221,7 @@ class DriverPage(object):
|
||||
return self.driver.execute_script(script)
|
||||
|
||||
@property
|
||||
def tabs_conut(self) -> int:
|
||||
def tabs_count(self) -> int:
|
||||
"""返回标签页数量"""
|
||||
try:
|
||||
return len(self.driver.window_handles)
|
||||
@ -239,7 +239,7 @@ class DriverPage(object):
|
||||
return self.driver.window_handles.index(self.driver.current_window_handle)
|
||||
|
||||
@property
|
||||
def current_tab_handle(safe) -> str:
|
||||
def current_tab_handle(self) -> str:
|
||||
"""返回当前标签页handle"""
|
||||
return self.driver.current_window_handle
|
||||
|
||||
@ -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:
|
||||
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(num_or_handle, int):
|
||||
page_handle = tabs[num_or_handle]
|
||||
elif isinstance(num_or_handle, str):
|
||||
page_handle = num_or_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,7 +289,11 @@ 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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user