From 4114e6826c57cdbe464e97e980df8e98095c9ee5 Mon Sep 17 00:00:00 2001 From: g1879 Date: Thu, 4 Jul 2024 18:11:45 +0800 Subject: [PATCH] =?UTF-8?q?4.1.0.0b1=E4=BC=98=E5=8C=96new=5Ftab()=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 5 ++--- DrissionPage/_base/browser.py | 7 +++---- DrissionPage/_units/clicker.py | 6 ++++-- DrissionPage/_units/waiter.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index 9660a96..027baa7 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -8,10 +8,9 @@ from ._base.browser import Browser from ._configs.chromium_options import ChromiumOptions from ._configs.session_options import SessionOptions -from ._pages.session_page import SessionPage - # 即将废弃 from ._pages.chromium_page import ChromiumPage +from ._pages.session_page import SessionPage from ._pages.web_page import WebPage -__version__ = '4.1.0.0b0' +__version__ = '4.1.0.0b1' diff --git a/DrissionPage/_base/browser.py b/DrissionPage/_base/browser.py index e5bc502..53ecc9e 100644 --- a/DrissionPage/_base/browser.py +++ b/DrissionPage/_base/browser.py @@ -222,10 +222,9 @@ class Browser(object): try: tab = self._run_cdp('Target.createTarget', **kwargs)['targetId'] except CDPError: - url = url or 'https://#' - tab = self.get_tab().add_ele(('a', {'href': url, - 'target': '_blank'})).click.for_new_tab(by_js=True) - return tab + data = ('a', {'href': url or 'https://#', 'target': '_new' if new_window else '_blank'}) + tab = self.get_mix_tab() if isinstance(obj, MixTab) else self.get_tab() + return tab.add_ele(data).click.for_new_tab(by_js=True) while tab not in self._drivers: sleep(.1) diff --git a/DrissionPage/_units/clicker.py b/DrissionPage/_units/clicker.py index f18014a..5f136bc 100644 --- a/DrissionPage/_units/clicker.py +++ b/DrissionPage/_units/clicker.py @@ -126,7 +126,8 @@ class Clicker(object): tid = self._ele.tab.browser.wait.new_tab(curr_tab=curr_tid) if not tid: raise RuntimeError('没有出现新标签页。') - return self._ele.tab.browser.get_tab(tid) + return (self._ele.tab.browser.get_mix_tab(tid) if self._ele.tab._type == 'MixTab' + else self._ele.tab.browser.get_tab(tid)) def at(self, offset_x=None, offset_y=None, button='left', count=1): """带偏移量点击本元素,相对于左上角坐标。不传入x或y值时点击元素中间点 @@ -194,7 +195,8 @@ class Clicker(object): tid = self._ele.tab.browser.wait.new_tab(timeout=timeout, curr_tab=curr_tid) if not tid: raise RuntimeError('没有出现新标签页。') - return self._ele.tab.browser.get_tab(tid) + return (self._ele.tab.browser.get_mix_tab(tid) if self._ele.tab._type == 'MixTab' + else self._ele.tab.browser.get_tab(tid)) def _click(self, client_x, client_y, button='left', count=1): """实施点击 diff --git a/DrissionPage/_units/waiter.py b/DrissionPage/_units/waiter.py index 9a26ecc..f471114 100644 --- a/DrissionPage/_units/waiter.py +++ b/DrissionPage/_units/waiter.py @@ -57,7 +57,7 @@ class BrowserWaiter(OriginWaiter): def new_tab(self, timeout=None, curr_tab=None, raise_err=None): """等待新标签页出现 :param timeout: 超时时间(秒),为None则使用页面对象timeout属性 - :param curr_tab: 指定当前最新的tab id,为None自动获取 + :param curr_tab: 指定当前最新的tab id,用于判断新tab出现,为None自动获取 :param raise_err: 等待失败时是否报错,为None时根据Settings设置 :return: 等到新标签页返回其id,否则返回False """