diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 2fcdf31..e3d2e75 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._pages.chromium_page import ChromiumPage from ._pages.mix_page import MixPage from ._pages.mix_page import MixPage as WebPage -__version__ = '4.1.0.0b3' +__version__ = '4.1.0.0b4' diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index 91ffa56..20bda69 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -376,15 +376,17 @@ class Chromium(object): while self.tabs_count != end_len and perf_counter() < end_time: sleep(.1) - def activate_tab(self, id_or_ind): + def activate_tab(self, id_ind_tab): """使标签页变为活动状态 - :param id_or_ind: 标签页id(str)或标签页序号(int),序号从1开始 + :param id_ind_tab: 标签页id(str)、Tab对象或标签页序号(int),序号从1开始 :return: None """ - 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) + if isinstance(id_ind_tab, int): + id_ind_tab += -1 if id_ind_tab else 1 + id_ind_tab = self.tab_ids[id_ind_tab] + elif isinstance(id_ind_tab, ChromiumTab): + id_ind_tab = id_ind_tab.tab_id + self._run_cdp('Target.activateTarget', targetId=id_ind_tab) def reconnect(self): """断开重连""" diff --git a/DrissionPage/_base/browser.pyi b/DrissionPage/_base/browser.pyi index 9ecfb3f..fa906ed 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: Union[int, str]) -> None: ... + def activate_tab(self, id_ind_tab: Union[int, str, ChromiumTab]) -> None: ... def _new_tab(self, obj, diff --git a/DrissionPage/_pages/chromium_page.py b/DrissionPage/_pages/chromium_page.py index f201cf4..aae5dbe 100644 --- a/DrissionPage/_pages/chromium_page.py +++ b/DrissionPage/_pages/chromium_page.py @@ -148,12 +148,12 @@ 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): + def activate_tab(self, id_ind_tab): """使标签页变为活动状态 - :param id_or_ind: 标签页id(str)或标签页序号(int),序号从1开始 + :param id_ind_tab: 标签页id(str)、Tab对象或标签页序号(int),序号从1开始 :return: None """ - self.browser.activate_tab(id_or_ind) + self.browser.activate_tab(id_ind_tab) def close(self): """关闭Page管理的标签页""" diff --git a/DrissionPage/_pages/chromium_page.pyi b/DrissionPage/_pages/chromium_page.pyi index 94ceb25..589a58d 100644 --- a/DrissionPage/_pages/chromium_page.pyi +++ b/DrissionPage/_pages/chromium_page.pyi @@ -101,7 +101,7 @@ 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 activate_tab(self, id_ind_tab: Union[int, str, ChromiumTab]) -> None: ... def close(self) -> None: ... diff --git a/DrissionPage/_units/setter.py b/DrissionPage/_units/setter.py index 3f0e441..972ab75 100644 --- a/DrissionPage/_units/setter.py +++ b/DrissionPage/_units/setter.py @@ -229,15 +229,6 @@ class BrowserSetter(BrowserBaseSetter): self._cookies_setter = BrowserCookiesSetter(self._owner) return self._cookies_setter - def tab_to_front(self, tab_or_id): - """激活标签页使其处于最前面 - :param tab_or_id: 标签页对象或id - :return: None - """ - if not isinstance(tab_or_id, str): # 传入Tab对象 - tab_or_id = tab_or_id.tab_id - self._owner.activate_tab(tab_or_id) - def auto_handle_alert(self, on_off=True, accept=True): """设置是否启用自动处理弹窗 :param on_off: bool表示开或关 @@ -274,6 +265,16 @@ class BrowserSetter(BrowserBaseSetter): raise ValueError(f'''mode参数只能是 '{"', '".join(types.keys())}' 之一,现在是:{mode}''') self._owner._dl_mgr.set_file_exists('browser', mode) + # ---------- 即将废弃 ---------- + def tab_to_front(self, tab_or_id): + """激活标签页使其处于最前面 + :param tab_or_id: 标签页对象或id + :return: None + """ + if not isinstance(tab_or_id, str): # 传入Tab对象 + tab_or_id = tab_or_id.tab_id + self._owner.activate_tab(tab_or_id) + class ChromiumBaseSetter(BrowserBaseSetter): @@ -427,17 +428,6 @@ class TabSetter(ChromiumBaseSetter): class ChromiumPageSetter(TabSetter): - def tab_to_front(self, tab_or_id=None): - """激活标签页使其处于最前面 - :param tab_or_id: 标签页对象或id,为None表示当前标签页 - :return: None - """ - if not tab_or_id: - tab_or_id = self._owner.tab_id - elif not isinstance(tab_or_id, str): # 传入Tab对象 - tab_or_id = tab_or_id.tab_id - self._owner.browser.activate_tab(tab_or_id) - def auto_handle_alert(self, on_off=True, accept=True, all_tabs=False): """设置是否启用自动处理弹窗 :param on_off: bool表示开或关 @@ -450,6 +440,18 @@ class ChromiumPageSetter(TabSetter): else: self._owner._alert.auto = accept if on_off else None + # ---------- 即将废弃 ---------- + def tab_to_front(self, tab_or_id=None): + """激活标签页使其处于最前面 + :param tab_or_id: 标签页对象或id,为None表示当前标签页 + :return: None + """ + if not tab_or_id: + tab_or_id = self._owner.tab_id + elif not isinstance(tab_or_id, str): # 传入Tab对象 + tab_or_id = tab_or_id.tab_id + self._owner.browser.activate_tab(tab_or_id) + class MixPageSetter(ChromiumPageSetter): def __init__(self, owner): @@ -589,6 +591,22 @@ class ChromiumFrameSetter(ChromiumBaseSetter): """ self._owner.frame_ele.set.attr(name, value) + def property(self, name, value): + """设置元素property属性 + :param name: 属性名 + :param value: 属性值 + :return: None + """ + self._owner.frame_ele.set.property(name=name, value=value) + + def style(self, name, value): + """设置元素style样式 + :param name: 样式名称 + :param value: 样式值 + :return: None + """ + self._owner.frame_ele.set.style(name=name, value=value) + class LoadMode(object): """用于设置页面加载策略的类""" diff --git a/DrissionPage/_units/setter.pyi b/DrissionPage/_units/setter.pyi index c6304b5..ca43f30 100644 --- a/DrissionPage/_units/setter.pyi +++ b/DrissionPage/_units/setter.pyi @@ -98,8 +98,6 @@ class BrowserSetter(BrowserBaseSetter): _owner: Chromium = ... _cookies_setter: BrowserCookiesSetter = ... - def tab_to_front(self, tab_or_id: Union[str, ChromiumTab]) -> None: ... - @property def cookies(self) -> BrowserCookiesSetter: ... @@ -159,8 +157,6 @@ class TabSetter(ChromiumBaseSetter): class ChromiumPageSetter(TabSetter): _owner: ChromiumPage = ... - def tab_to_front(self, tab_or_id: Union[str, ChromiumTab] = None) -> None: ... - def auto_handle_alert(self, on_off: bool = True, accept: bool = True, all_tabs: bool = False) -> None: ...