diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index fb6e940..91ffa56 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -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: 标签页id(str)或标签页序号(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): """断开重连""" diff --git a/DrissionPage/_base/browser.pyi b/DrissionPage/_base/browser.pyi index aa3978c..9ecfb3f 100644 --- a/DrissionPage/_base/browser.pyi +++ b/DrissionPage/_base/browser.pyi @@ -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, diff --git a/DrissionPage/_pages/chromium_page.py b/DrissionPage/_pages/chromium_page.py index 7552aea..f201cf4 100644 --- a/DrissionPage/_pages/chromium_page.py +++ b/DrissionPage/_pages/chromium_page.py @@ -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: 标签页id(str)或标签页序号(int),序号从1开始 + :return: None + """ + self.browser.activate_tab(id_or_ind) + def close(self): """关闭Page管理的标签页""" self.close_tabs(self.tab_id) diff --git a/DrissionPage/_pages/chromium_page.pyi b/DrissionPage/_pages/chromium_page.pyi index 22c31fc..94ceb25 100644 --- a/DrissionPage/_pages/chromium_page.pyi +++ b/DrissionPage/_pages/chromium_page.pyi @@ -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]], diff --git a/DrissionPage/_units/clicker.py b/DrissionPage/_units/clicker.py index 15a6b9d..73de7c3 100644 --- a/DrissionPage/_units/clicker.py +++ b/DrissionPage/_units/clicker.py @@ -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,