mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
修改关闭标签页功能,未完成
This commit is contained in:
parent
0172757ccf
commit
3af48126ea
@ -303,31 +303,28 @@ class DriverPage(BasePage):
|
|||||||
:param num_or_handles: 要保留的标签页序号或handle,可传入handle组成的列表或元组
|
:param num_or_handles: 要保留的标签页序号或handle,可传入handle组成的列表或元组
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
try:
|
if num_or_handles is None:
|
||||||
tab = int(num_or_handles)
|
reserve_tabs = (self.current_tab_handle,)
|
||||||
except (ValueError, TypeError):
|
elif isinstance(num_or_handles, (int, str)):
|
||||||
tab = num_or_handles
|
reserve_tabs = (num_or_handles,)
|
||||||
|
elif isinstance(num_or_handles, (list, tuple)):
|
||||||
tabs = self.driver.window_handles
|
reserve_tabs = num_or_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,)
|
|
||||||
elif isinstance(tab, (list, tuple)):
|
|
||||||
page_handle = tab
|
|
||||||
else:
|
else:
|
||||||
raise TypeError('num_or_handle参数只能是int、str、list 或 tuple类型。')
|
raise TypeError('num_or_handle参数只能是int、str、list 或 tuple类型。')
|
||||||
|
|
||||||
|
tabs = self.driver.window_handles
|
||||||
|
reserve_tabs = set(i if isinstance(i, str) else tabs[i] for i in reserve_tabs)
|
||||||
|
|
||||||
for i in tabs: # 遍历所有标签页,关闭非保留的
|
for i in tabs: # 遍历所有标签页,关闭非保留的
|
||||||
if i not in page_handle:
|
if i not in reserve_tabs:
|
||||||
self.driver.switch_to.window(i)
|
self.driver.switch_to.window(i)
|
||||||
self.driver.close()
|
self.driver.close()
|
||||||
|
|
||||||
self.to_tab(0)
|
self.to_tab(0)
|
||||||
|
|
||||||
|
def close_tab(self, num_or_handles: Union[int, str, list, tuple] = None):
|
||||||
|
pass
|
||||||
|
|
||||||
def to_tab(self, num_or_handle: Union[int, str] = 0) -> None:
|
def to_tab(self, num_or_handle: Union[int, str] = 0) -> None:
|
||||||
"""跳转到标签页 \n
|
"""跳转到标签页 \n
|
||||||
:param num_or_handle: 标签页序号或handle字符串,序号第一个为0,最后为-1
|
:param num_or_handle: 标签页序号或handle字符串,序号第一个为0,最后为-1
|
||||||
@ -525,3 +522,17 @@ class DriverPage(BasePage):
|
|||||||
alert.accept()
|
alert.accept()
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def _get_handles(page: DriverPage, num_or_handles: Union[int, str, list, tuple] = None):
|
||||||
|
if num_or_handles is None:
|
||||||
|
reserve_tabs = (page.current_tab_handle,)
|
||||||
|
elif isinstance(num_or_handles, (int, str)):
|
||||||
|
reserve_tabs = (num_or_handles,)
|
||||||
|
elif isinstance(num_or_handles, (list, tuple)):
|
||||||
|
reserve_tabs = num_or_handles
|
||||||
|
else:
|
||||||
|
raise TypeError('num_or_handle参数只能是int、str、list 或 tuple类型。')
|
||||||
|
|
||||||
|
tabs = page.driver.window_handles
|
||||||
|
return set(i if isinstance(i, str) else tabs[i] for i in reserve_tabs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user