activate_tab的tab_id参数改为id_or_ind

This commit is contained in:
g1879 2024-07-08 07:16:41 +08:00
parent 4cf63e9b08
commit ea397923f6
5 changed files with 17 additions and 5 deletions

View File

@ -376,12 +376,15 @@ class Chromium(object):
while self.tabs_count != end_len and perf_counter() < end_time:
sleep(.1)
def activate_tab(self, tab_id):
def activate_tab(self, id_or_ind):
"""使标签页变为活动状态
:param tab_id: 标签页id
:param id_or_ind: 标签页idstr或标签页序号int序号从1开始
:return: None
"""
self._run_cdp('Target.activateTarget', targetId=tab_id)
if isinstance(id_or_ind, int):
id_or_ind += -1 if id_or_ind else 1
id_or_ind = self.tab_ids[id_or_ind]
self._run_cdp('Target.activateTarget', targetId=id_or_ind)
def reconnect(self):
"""断开重连"""

View File

@ -135,7 +135,7 @@ class Chromium(object):
mix: bool = False,
as_id: bool = False) -> List[ChromiumTab, str]: ...
def activate_tab(self, tab_id: str) -> None: ...
def activate_tab(self, tab_id: Union[int, str]) -> None: ...
def _new_tab(self,
obj,

View File

@ -148,6 +148,13 @@ class ChromiumPage(ChromiumBase):
"""
return self.browser.new_tab(url=url, new_window=new_window, background=background, new_context=new_context)
def activate_tab(self, id_or_ind):
"""使标签页变为活动状态
:param id_or_ind: 标签页idstr或标签页序号int序号从1开始
:return: None
"""
self.browser.activate_tab(id_or_ind)
def close(self):
"""关闭Page管理的标签页"""
self.close_tabs(self.tab_id)

View File

@ -101,6 +101,8 @@ class ChromiumPage(ChromiumBase):
def new_tab(self, url: str = None, new_window: bool = False, background: bool = False,
new_context: bool = False) -> ChromiumTab: ...
def activate_tab(self, tab_id: Union[int, str]) -> None: ...
def close(self) -> None: ...
def close_tabs(self, tabs_or_ids: Union[str, ChromiumTab, List[Union[str, ChromiumTab]],

View File

@ -208,7 +208,7 @@ class Clicker(object):
:param count: 点击次数
:return: None
"""
self._ele.owner.actions.move_to((loc_x, loc_y), duration=.1)
self._ele.owner.actions.move_to((loc_x, loc_y), duration=.05)
self._ele.owner._run_cdp('Input.dispatchMouseEvent', type='mousePressed', x=view_x,
y=view_y, button=button, clickCount=count, _ignore=AlertExistsError)
self._ele.owner._run_cdp('Input.dispatchMouseEvent', type='mouseReleased', x=view_x,