mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
4.1.0.0b1优化new_tab()逻辑
This commit is contained in:
parent
c26a3d78b2
commit
4114e6826c
@ -8,10 +8,9 @@
|
|||||||
from ._base.browser import Browser
|
from ._base.browser import Browser
|
||||||
from ._configs.chromium_options import ChromiumOptions
|
from ._configs.chromium_options import ChromiumOptions
|
||||||
from ._configs.session_options import SessionOptions
|
from ._configs.session_options import SessionOptions
|
||||||
from ._pages.session_page import SessionPage
|
|
||||||
|
|
||||||
# 即将废弃
|
# 即将废弃
|
||||||
from ._pages.chromium_page import ChromiumPage
|
from ._pages.chromium_page import ChromiumPage
|
||||||
|
from ._pages.session_page import SessionPage
|
||||||
from ._pages.web_page import WebPage
|
from ._pages.web_page import WebPage
|
||||||
|
|
||||||
__version__ = '4.1.0.0b0'
|
__version__ = '4.1.0.0b1'
|
||||||
|
@ -222,10 +222,9 @@ class Browser(object):
|
|||||||
try:
|
try:
|
||||||
tab = self._run_cdp('Target.createTarget', **kwargs)['targetId']
|
tab = self._run_cdp('Target.createTarget', **kwargs)['targetId']
|
||||||
except CDPError:
|
except CDPError:
|
||||||
url = url or 'https://#'
|
data = ('a', {'href': url or 'https://#', 'target': '_new' if new_window else '_blank'})
|
||||||
tab = self.get_tab().add_ele(('a', {'href': url,
|
tab = self.get_mix_tab() if isinstance(obj, MixTab) else self.get_tab()
|
||||||
'target': '_blank'})).click.for_new_tab(by_js=True)
|
return tab.add_ele(data).click.for_new_tab(by_js=True)
|
||||||
return tab
|
|
||||||
|
|
||||||
while tab not in self._drivers:
|
while tab not in self._drivers:
|
||||||
sleep(.1)
|
sleep(.1)
|
||||||
|
@ -126,7 +126,8 @@ class Clicker(object):
|
|||||||
tid = self._ele.tab.browser.wait.new_tab(curr_tab=curr_tid)
|
tid = self._ele.tab.browser.wait.new_tab(curr_tab=curr_tid)
|
||||||
if not tid:
|
if not tid:
|
||||||
raise RuntimeError('没有出现新标签页。')
|
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):
|
def at(self, offset_x=None, offset_y=None, button='left', count=1):
|
||||||
"""带偏移量点击本元素,相对于左上角坐标。不传入x或y值时点击元素中间点
|
"""带偏移量点击本元素,相对于左上角坐标。不传入x或y值时点击元素中间点
|
||||||
@ -194,7 +195,8 @@ class Clicker(object):
|
|||||||
tid = self._ele.tab.browser.wait.new_tab(timeout=timeout, curr_tab=curr_tid)
|
tid = self._ele.tab.browser.wait.new_tab(timeout=timeout, curr_tab=curr_tid)
|
||||||
if not tid:
|
if not tid:
|
||||||
raise RuntimeError('没有出现新标签页。')
|
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):
|
def _click(self, client_x, client_y, button='left', count=1):
|
||||||
"""实施点击
|
"""实施点击
|
||||||
|
@ -57,7 +57,7 @@ class BrowserWaiter(OriginWaiter):
|
|||||||
def new_tab(self, timeout=None, curr_tab=None, raise_err=None):
|
def new_tab(self, timeout=None, curr_tab=None, raise_err=None):
|
||||||
"""等待新标签页出现
|
"""等待新标签页出现
|
||||||
:param timeout: 超时时间(秒),为None则使用页面对象timeout属性
|
:param timeout: 超时时间(秒),为None则使用页面对象timeout属性
|
||||||
:param curr_tab: 指定当前最新的tab id,为None自动获取
|
:param curr_tab: 指定当前最新的tab id,用于判断新tab出现,为None自动获取
|
||||||
:param raise_err: 等待失败时是否报错,为None时根据Settings设置
|
:param raise_err: 等待失败时是否报错,为None时根据Settings设置
|
||||||
:return: 等到新标签页返回其id,否则返回False
|
:return: 等到新标签页返回其id,否则返回False
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user